Cut Pointintn,m,stamp,low[1005],dfn[1005],iscut[1005];//Iscut recorded as a cut pointvector<int> vec[1005];voidTarjan (intIndexintFA) { intChild=0; Low[index]=dfn[index]=++Stamp; for(intI=0; I<vec[index].size (); i++) { inttmp=Vec[index][i]; if(!Dfn[tmp]) { Child++; Tarjan (Tmp,index); Low[index]=min (low[index],low[tmp]); if(low[tmp]>=Dfn[index]) Iscut[index]=1; } Else if(Dfn[tmp]<dfn[index] && tmp!=FA) {Low[index]=min (low[index],dfn[tmp]); } } if(fa<0&& child==1) Iscut[index]=0;}
Find a bridge
inthead[n],dfn[n],low[n],belong[n],de[n],stack[n],bridge[m][2],ins[n],dcnt,bcnt,top,bnum;structedge{intU,v,next;} e[2*M];voidAddintW NintVintk) {e[k].u= u; E[K].V = v; E[k].next = Head[u]; Head[u] = k++; E[K].U= V; E[K].V = u; E[k].next = Head[v]; HEAD[V] = k++;}voidDfsintW NintFA) {Dfn[u]= Low[u] = + +dcnt; stack[++top] = u; Ins[u] =1;//the INS array is used to record whether this connected block has traversed for(intK=head[u]; k!=-1; k=E[k].next) { intv =e[k].v; if(v = = FA)Continue; if(!dfn[v])//Tree Side{DFS (v,u); Low[u]=min (Low[u], low[v]); if(Low[v] > Dfn[u])//Edge (U,V) is a bridge, you can count one edge connected branch { //Save Bridgebridge[bnum][0] = u;//Bridge is used to record the elements on both sides of the bridge, and U is the parent node.bridge[bnum++][1] =v; ++bcnt;//bcnt used to record the number of double unicom blocks while(true) { intx = stack[top--]; INS[X]=0; BELONG[X]= bcnt;//belong record node x belongs to which connected block if(x = = v) Break; }//Note that the point U is not out of the stack because the point u belongs to another edge connected component } } Else if(Ins[v])//Back to EdgeLow[u] =min (Low[u], dfn[v]); //Cross Edge (Dfn[v] &&!ins[v]), skip }}
Tarjan double unicom for cutting point and bridge template