Tarjan double unicom for cutting point and bridge template

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.