FIG cut point and bridge

First, the definition

Cut point undirected graph a connection diagram, if deleting a vertex, FIG no together (i.e. between any two points can not reach each other), so that said apex is cut point or: cut point is a point when and not only communicated to delete the edge points and the Figure associated with the point becomes.

FIG cutting edge / Bridge: a free, if deleting one edge, no communication to FIG communication drawing, this edge is on the cutting edge. Or: the edge is a cutting edge if and only if the change does not communicate FIG delete the edge.

two.

Seeking cut point, the bridge using DFS (deep search) to find cut point and bridge. First clear the following points: 1, dfs figure is equivalent to traversing the corresponding dfs tree.

2, undirected dfs tree, regardless of which point to the root can be done through all the points.

3, the tree dfs undirected graph, there is no lateral cross edge (edge ​​connecting two subtrees).

Of the original depth-first search, depth-first search will generate a spanning tree. Defined DFS [u] for the u is traversed in depth first search spanning sequence number, low [u] for the u or his subtree can be traced back to the first side of the non-parent-child node.

① is a cut vertex point, one of the following conditions:

1) .u is the root, u has two or more branches / u has more than one sub-tree;

2) .u not the root, satisfying existence (u, v) as a side branch (also known as parent-child edges, that is, u and v father in the search tree), (u, v) is a tree edge and low [v] > = dfn [u]. low (u) = min {dfn (u), low (v) if (u, v) is the side branches / parent-child edges, dfn (v) if (u, v) is a backward edge / edge throwback}

② bridge undirected edge (u, v), if and only if (u, v) is the side branches, and satisfying the dfn [u] <low [v]. Note: 1, to facilitate the programming, we have adopted low [v] to judge u. (Theoretically low [u] may be determined cut point)

Third, the program

Prepare two arrays low and dfn. Low array is an array of tags, Dfn value of the root node strongly connected subgraph record the point where the search where the sub-tree (very Raozui, look down and you'll understand). dfn array of recording time to search for the point, which is the first of several search this point. According to a few rules, the search run through FIG. (Without backtracking) and the operation of the stack, we can get the strongly connected components of the directed graph.

1. array initialization: When you first search for the point p, dfn and low value of the array are to that point in time.

2. Stack: Each search to a point, it will be pressed into the top of the stack. 3. When there is the point p '(when time DFN [p]) joined, at this time if p' and the point p on the stack (father and son side), the low value of p min (low (p), dfn ( p ')).

'(When time DFN [p]) joined, at this time if p' 4. When the point p and the point p has not stack (after the edge), the low value of p min (low (p), low (p ')).

5. Whenever a search point through the above operations (i.e. sub-tree have all been traversed) is equal dfn low value, then it is well above its element popped off the stack. These elements of the stack a strongly connected components.

6. Continue search (perhaps replacing the starting point of the search, because the whole it is possible divided into two parts disconnected directed graph), until all the points are traversed.

Since only accessed once for each vertex, each edge visited only once, we can determine in O (n + m) time to have strongly connected components of FIG.

Fourth, the application 1, a higher degree of communication of a communication network represented by FIG, more reliable system which, regardless of which site it appears to be a

Suffered external damage or impaired, will not affect the normal operation of the system; 2, if a heavy aviation network connectivity, then when a route is closed for any reason, such as weather, visitors can still take a detour from other routes;

3, when a large-scale integrated circuit critical path is designed to re-communication, then in the case of some component failure, the function of the entire film is not affected, on the contrary, in the war, transport lines to destroy enemy , just destruction of articular point in its transport network can be. Cut point template:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
using namespace std;
const int N=1000005;
int t,cnt,head[N],son[N],dfn[N],low[N],n,ans,m,root;
bool is_ok[N];
struct Node{
    int u,v,next;
}edge[N];
void push(int u,int v){
    ++cnt;
    edge[cnt].u=u;
    edge[cnt].v=v;
    edge[cnt].next=head[u];
    head[u]=cnt;
}
void tarjan(int v,int u){
    low[v]=dfn[v]=++t;
    for(int i=head[v];i!=-1;i=edge[i].next){
        ++son[v];
        int v1=edge[i].v;
        if(dfn[v1]==-1){
            tarjan(v1,v);
            low[v]=min(low[v],low[v1]);
            if(v==root&&son[v]>=2){
                is_ok[v]=true;
            }
            else if(v!=root&&low[v1]>=dfn[v]){
                is_ok[v]=true;
            }
        }
        else if(v1!=u){
            low[v]=min(low[v],dfn[v1]);
        }
    }
}
int main(){
    memset(head,-1,sizeof(head));
    memset(dfn,-1,sizeof(dfn));
    memset(is_ok,false,sizeof(is_ok));
    int u,v;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        push(u,v);
        push(v,u);
    }
    root=u;
    tarjan(u,0);
    for(int i=1;i<=n;i++){
        if(is_ok[i]){
            ++ans;
        }
    }
    printf("%d\n",ans);
    for(int i=1;i<=n;i++){
        if(is_ok[i]){
            printf("%d ",i);
        }
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/ukcxrtjr/p/11119846.html