The double-link component of the graph without direction

Source: Internet
Author: User

The difference between the double and the side of the point I have already discussed in the previous article, this article talks about the method of the side double.

Because it is the side of the double, it is decided that the side of the two must not contain a bridge, but can contain cutting top.

So the only restriction we have on the side is that we don't go through the bridge.

As a result, we can be divided into two Dfs, the first to find all the bridge, the second DFS when the entire map, as long as the guarantee does not pass through the bridge.

#include <cstdio>#include<cstring>#include<algorithm>#include<vector>#include<stack>using namespacestd;Const intMAXN = the, MAXM = MAXN *2;intN, M, tot, Dfs_clock, bcc_cnt;intH[MAXN], DFN[MAXN], LOW[MAXN], ISCUT[MAXN], VIS[MAXN];structedge{intV, Next, Isbridge;} A[maxm];vector<int>BCC[MAXN];voidAddintXinty) {A[TOT].V=y; A[tot].next=H[x]; H[X]= tot++;}intDfsintUintFA) {    intLowu = Dfn[u] = + +Dfs_clock; intChild =0;  for(inti = H[u]; ~i; i =A[i].next) {        intv =a[i].v; if(!Dfn[v]) { Child++; intLOWV =Dfs (v, u); Lowu=min (Lowu, LOWV); if(LOWV >=Dfn[u]) {Iscut[u]=1; }            if(Lowv >Dfn[u]) {//printf ("%d-%d\n", u, v);A[i].isbridge =1; A[i^1].isbridge =1; }        }Else if(Dfn[v] < Dfn[u] && v! =FA) {Lowu=min (Lowu, dfn[v]); }    }    if(FA = =0&& Child = =1) {Iscut[u]=0; } Low[u]=Lowu; returnLowu;}voidDFS2 (intUintFA)    {bcc[bcc_cnt].push_back (U); Vis[u]=1;  for(inti = H[u]; ~i; i =A[i].next) {        intv =a[i].v; if(v = = FA | | a[i].isbridge | | VIS[V])Continue;    DFS2 (V, u); } }intMain () {Freopen ("non-graph double unicom component. in","R", stdin); scanf ("%d%d", &n, &m); memset (H,-1,sizeofh); tot = Dfs_clock =0;  for(inti =1; I <= m; i++)    {        intx, y; scanf ("%d%d", &x, &y); Add (x, y);    Add (y, x); } DFS (1,0);  for(inti =1; I <= N; i++)        if(!Vis[i]) {bcc_cnt++;            Bcc[bcc_cnt].clear (); DFS2 (i,0); }     for(inti =1; I <= bcc_cnt; i++)    {         for(intj =0; J < Bcc[i].size (); J + +) printf ("%d", Bcc[i][j]); printf ("\ n"); }    return 0;}

The double-link component of the graph without direction

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.