Cut Point
Dfs search tree : When using DFS to traverse graphs, we can get a DFS search tree according to the different traversal order.
Tree Edge : (called a parent-child edge ), which can be understood as the edge through which an unreachable node is accessed during a DFS process.
Back Edge : ( atavistic Edge , back Edge ), which can be understood as the edge through which a node has been accessed during the DFS process.
The algorithm was invented by R.tarjan. Observing the DFS search tree, we can see that there are two types of nodes that can be cut points:
- to the root node u, if it has two or more subtree, then the root node U is a cut point;
- For non-leaf node U (non-root node), if the node with a subtree does not have a back edge to the ancestor node of U, the node of the root node and the subtree of U are no longer connected after removing U, then node u is the cut point.
Http://cogs.pro/cogs/problem/problem.php?pid=8
#include <cstdio>#include<algorithm>using namespacestd;structedge{intTo,next;} edge[10005];intfi[ the],top,low[ the],fa[ the],dfn[ the],kid[ the];BOOLvis[ the],cut[ the];voidAdd_edge (int from,intTo ) {edge[++top].next=fi[ from],fi[ from]=top,edge[top].to=to ; edge[++top].next=fi[to],fi[to]=top,edge[top].to= from;}voidDfsintx) { //Record DFS traversal order Static intCounter =0; DFN[X]=low[x]=++counter; VIS[X]=1; if(x==4) x=4; for(intto = fi[x];to;to=Edge[to].next) { intv=edge[to].to; if(!vis[v]) {//node v is not accessed, then (U,V) is a tree edgefa[v]=x;kid[x]++; DFS (v); LOW[X]=min (low[x],low[v]); if(Low[v]>=dfn[x]) cut[x]=1; } Else if(V!=fa[x]) {//node v has been accessed, then (U,V) is a back edgelow[x]=min (low[x],dfn[v]); } }}intMain () {Freopen ("gd.in","R", stdin); Freopen ("Gd.out","W", stdout); intn,a,b,ans=0; scanf ("%d",&N); while(~SCANF ("%d%d",&a,&b)) Add_edge (A, b); DFS (1); if(kid[1]<2) cut[1]=0; for(intI=1; i<=n;i++){ if(Cut[i]) ans++; } printf ("%d\n", ans); for(intI=1; i<=n;i++){ if(Cut[i]) printf ("%d\n", i); } return 0;}
Find a bridge
For an edge (U,V), U is an ancestor, and if all the subtrees of V do not point to a point that is first traversed (U,V) is the bridge
Unicom-cut points and bridges for graphs