[HIHO1184] Connectivity two • Two-connected components of the edge (dual-connected components)

Source: Internet
Author: User

Title Link: http://hihocoder.com/problemset/problem/1184

Test instructions naked, wrote a blog write down the output posture.

1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%lld", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (int i = 0; i < (len); i++) the #defineFor (I, A, Len) for (int i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFull (a) memset ((a), 0x7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineOnenum (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongULL; +typedef pair<int,int>PII; thetypedef pair<string,int>psi; -typedef PAIR&LT;LL, Ll>PLL; $typedef map<string,int>MSI; thetypedef vector<int>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; -  in Const intMAXN =50020; the Const intMAXM =500100; thetypedefstructEdge { About     intu, v; the     intnext, I; the     BOOLcut; the Edge () {} +Edge (intUuintvvintII): U (UU), V (vv), I (ii) {} - }edge; the Bayi Edge EDGE[MAXM]; the intHEAD[MAXN], ecnt; the intN, M; - intDFN[MAXN]; - intLOW[MAXN]; the BOOLVIS[MAXN]; the BOOLCUT[MAXN]; the VI Bridge; the intST[MAXN], top; - intBELONG[MAXN], bcnt; the VI tmp; the intret; the 94 voidinit () { theCLR (Head,-1); Cls (Low); Cls (DFN); theCls (VIS); Cls (cut); Cls (ST); RET =0; theBCNT =1; top =0; ECNT =0; bridge.cl ();98 } About  - voidAdde (intUuintvvintII) {101EDGE[ECNT] =Edge (UU, VV, ii);102Edge[ecnt].cut =0;103Edge[ecnt].next =Head[uu];104Head[uu] = ecnt++; the }106 107 108 voidTarjan (intUintDintp) {109Low[u] = Dfn[u] =D; theSt[++top] =u;111Vis[u] =1; the      for(inti = Head[u]; ~i; I=Edge[i].next) {113         intv =edge[i].v; the         intID =edge[i].i; the         if(p = = ID)Continue; the         if(!Dfn[v]) {117Tarjan (V, d+1, id);118Low[u] =min (Low[u], low[v]);119             if(Low[v] >Dfn[u]) { - BRIDGE.PB (i);121Edge[i].cut = edge[i^1].cut =1;122             }123         }124         ElseLow[u] =min (Low[u], dfn[v]); the     }126     if(Low[u] = =Dfn[u]) {127 tmp.cl (); -         intv;129BCNT =0x7f7f7f; the          Do {131v = st[top--]; theVIS[V] =0;133BCNT =min (bcnt, v);134 TMP.PB (v);135} while(V! =u);136Rep (i, Tmp.size ()) belong[tmp[i]] =bcnt;137ret++;138     }139 } $ 141 intMain () {142     //FRead ();143     intu, v;144      while(~SCANF ("%d%d", &n, &m)) {145 init ();146for (I,1, m+1) {147 Rint (U); Rint (v);148 adde (U, V, i);149 Adde (V, U, i); Max         }151for (I,1, n+1) { the             if(!dfn[i]) Tarjan (i,1, -1);153         }154printf"%d\n", ret);155for (I,1, n+1) printf ("%d", Belong[i]);156printf"\ n");157     }158Rt0;159}

[HIHO1184] Connectivity two • Two-connected components of the edge (dual-connected components)

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.