Tarjan algorithm of Double Unicom

Source: Internet
Author: User

Transferred from: https://www.zhihu.com/question/40746887/answer/88428236

There are three kinds of connected components: side double connected component, point double connected component, Strong connected component, the first two belong to undirected graph, the latter belongs to the graph

Defined:

The two connected components are divided into double connected component and edge double connected component. If an undirected graph removes any one of the nodes (an edge) does not change the connectivity of this graph, that is, there is no cut point (bridge), it is called a point (edge) double-connected graph. Each maximal point (edge) double-connected sub-graph in an undirected graph is called a point (edge) double-connected component of this undirected graph.

The code is as follows:

Point double unicom struct edge{int u,v; Edge (int _u,int _v): U (_u), V (_v) {}}edge[maxn];int dfn[maxn],low[maxn],cut[maxn],bccno[maxn];vector<int>gra[    Maxn],bcc[maxn];stack<int>stk;int cnt,bcnt;void Tarjan (int f,int u) {dfn[u]=low[u]=++cnt;    int child=0;    int sz=gra[u].size ();        for (int i=0;i<sz;i++) {int id=gra[u][i];        int v=edge[id].v;            if (!dfn[v]) {Stk.push (ID);            child++;            Tarjan (U,V);            Low[u]=min (Low[u],low[v]);                if (Low[v]>=dfn[u]) {cut[u]=1;                Bcc[++bcnt].clear ();                    while (1) {int id=stk.top ();                    Stk.pop ();                    int uu=edge[id].u;                    int vv=edge[id].v;                        if (bccno[uu]!=bcnt) {bcc[bcnt].push_back (UU);                    bccno[uu]=bcnt;            } if (bccno[vv]!=bcnt) {bcc[bcnt].push_back (vv);            bccno[vv]=bcnt;                    } if (uu==u&&vv==v) {break;            }}}}else if (dfn[v]<dfn[u]&&v!=f) {Stk.push (ID);        Low[u]=min (Low[u],dfn[v]);    }} if (f<0&&child==1) {cut[u]=0;    }} side Dual link struct edge{int u,v; Edge (int _u,int _v): U (_u), V (_v) {}}edge[maxn];int dfn[maxn],low[maxn],bccno[maxn];vector<int>gra[maxn],bcc[    Maxn];bool isb[maxn];void Tarjan (int f,int u) {dfn[u]=low[u]=++cnt;    int sz=gra[u].size ();        for (int i=0;i<sz;i++) {int id=gra[u][i];        int v=edge[id].v;            if (!dfn[v]) {Tarjan (u,v);            Low[u]=min (Low[u],low[v]);            if (Low[v]>dfn[u]) {isb[id]=isb[id^1]=1;        }}else if (dfn[v]<dfn[u]&&v!=f) {low[u]=min (low[u],dfn[v]);    }}}void dfs (int u) {dfn[u]=1;    bccno[u]=bcnt; int SZ=GRA[u].size ();        for (int i=0;i<sz;i++) {int id=gra[u][i];        int v=edge[id].v;        if (Isb[id]) {continue;        } if (!dfn[v]) {DFS (v);        }}}int Main () {for (int i=1;i<=n;i++) {if (!dfn[i]) {Tarjan ( -1,i);    }} memset (Dfn,0,sizeof (DFN));            for (int i=1;i<=n;i++) {if (!dfn[i]) {bcnt++;        DFS (i); }    }}

  

Tarjan algorithm of Double Unicom

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.