Cut Algorithm Algorithm cutting edge point of the graph of FIG.

Cut Algorithm Algorithm cutting edge point of the graph of FIG.

Split point

In an undirected connected graphs, if deleting a vertex, FIG no communication (i.e., can not reach each other between any two points), we call such a vertex is cut point (or called top cut).

In the above figure 2 is cut vertex point, because the No. 2 deleted, nowhere 4,5, 1,6 do not pass.

The method is easy to think of is: in order to delete each vertex, then dfs or bfs to check whether the map is still connected. If you delete a vertex, resulting diagrams are no longer communicating, then just delete the apex of that cut.

Time complexity of this method is O (N (N + M)).

Below find low-complexity method to solve.

After traversing the FIG dfs, as shown, the vertex numbers are circled numbers, the number of top right vertex of the circle indicates the first number to be accessed, called "time stamp" while traversing.

Thinking

If we access to u when dfs point where FIG u will be divided into two portions points. Part has been accessed point, the other part is not accessed point. If u cut point is the point, then at least a point after point without u point is never going anyway already visited the rest of the points have not been accessed in a. If u to the rear, the figure vertex v there is no point visited, how to judge any previously visited without going through the v in u of whether it can return to a point? u is v's father, and previously visited vertex is the ancestor. That is, how to detect without v u after his father's ancestors also could return. That is to once again v dfs, but the traversal without u, see if you can return to the ancestors. U can not cut is the point.

We need an array of low to record each vertex in the vertex without a parent, you can return to a minimum "time stamp."

For a vertex u, if at least one vertex V (u son) is present, such that low [v]> = num [ u], i.e. not return ancestors, then the point u cut point.




FIG adjacency matrix with the above-described memory, time complexity is O (N ^ 2). Because edge time processing requires N ^ 2.

If the change has adjacent table storage, calculation complexity is reduced to O (M + N).

Cutting edge

I.e., a non, if a delete edges, no longer communicating FIG connected graph, the cutting edge becomes.

求割边时,只需要将求割点的算法修改一个符号即可。只需要将 low[v]>=num[u] 改为 low[v]>num[u]。

因为 low[v]>=num[u] 代表的是 v 不可能在不经过父亲 u 而回到祖先。如果 low[v]=num[u],表示还可以回到父亲。而 low[v]>num[u] 则表示连父亲都回不到了。倘若顶点 v 不能回到祖先,也没有另外一条路能回到父亲,那么 u-v 就是割边。


同样,用邻接矩阵存储图,时间复杂度为 O(N^2)。如果改有邻接表存储,算法时间复杂度降为 O(M+N)。

Guess you like

Origin www.cnblogs.com/tttfu/p/11274097.html