Tarjan to find strong connected components
In a direction diagram, if there is a two point between the path to reach each other , then the two points of the strong Unicom , if any two points are strong unicom, then called this figure is a strong unicom map ; a graph of the great strong Unicom is called Strong Unicom Components .
The algorithm can find all the strong unicom components of a graph in the time.
Indicates the time to enter the node.
Represents the earliest time from the midpoint of the stack that can be traced
If a point has been updated in the stack
Otherwise the backtracking is performed and updated after backtracking
#include <iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<stack>using namespacestd;intN,m,tot,ind,ans;intdfn[200005],low[200005],last[200005];BOOLins[200005];stack<int>s;structhh{intFr,to,next;} e[500005];voidAddintFrintTo ) {e[++tot].to=to;e[tot].fr=fr; E[tot].next=LAST[FR]; LAST[FR]=tot;}voidTarjan (intNow ) { inti,j; S.push (now); Ins[now]=true; Low[now]=dfn[now]=++dex; for(i=last[now];i;i=e[i].next)if(!Dfn[e[i].to]) {Tarjan (e[i].to); Low[now]=min (low[now],low[e[i].to]); } Else if(Ins[e[i].to]) low[now]=min (low[now],dfn[e[i].to]); if(dfn[now]==Low[now]) {CNT=0; Do{J=s.top (); S.pop (); INS[J]=false; CNT++; } while(j!=Now ); Ans=Max (ans,cnt); }}intMain () {inti,j,u,v; scanf ("%d%d",&n,&m); for(i=1; i<=m;i++) {scanf ("%d%d",&u,&v); Add (U,V); } for(i=1; i<=n;i++) if(!Dfn[i]) Tarjan (i); printf ("%d", ans); return 0;}
Tarjan to cut points
In an undirected graph, the point is the cut point of the graph if the number of connected blocks in the graph is increased after the delete point is removed.
For non-root nodes on the search tree, if there are child nodes that are satisfied, that is, an ancestor that cannot be reached upward, it is a cut point.
For the root node on the search tree, it is a cut point if its number of child nodes.
voidTarjan (intXintFA) { inti,j; DFN[X]=low[x]=++Dex; for(i=last[x];i;i=E[i].next) { ++T[x]; if(!Dfn[e[i].to]) {Tarjan (e[i].to,x); LOW[X]=min (low[x],low[e[i].to]); if(x==root&&t[x]>=2) opt[x]=true; Else if(X!=root&&low[e[i].to]>=dfn[x]) opt[x]=true; } Else if(E[I].TO!=FA) low[x]=min (low[x],dfn[e[i].to]); }}
Tarjan Cutting Edge
For the current node, the edge is cut if there is a junction in the Adjacency point.
voidTarjan (intXintFA) { inti,j; LOW[X]=dfn[x]=++Dex; for(i=last[x];i;i=e[i].next)if(e[i].to!=FA) { if(Dfn[e[i].to]) low[x]=min (low[x],dfn[e[i].to]); Else{Tarjan (e[i].to,x); LOW[X]=min (low[x],low[e[i].to]); if(Low[e[i].to]>dfn[x]) opt[e[i].id]=true; } }}
"Learning and finishing" Tarjan: Strong connected Components + cutting points + cutting edges