1#include <cstdio>2#include <cstring>3#include <cmath>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <queue>8#include <stack>9#include <Set>Ten #defineESP (1E-6) One #defineINF (0X3F3F3F3F) A #defineL (a) ((a) <<1) - #defineR (a) ((a) <<1|1) - #defineB (A) (1<< (a)) the #defineRep (i,a,b) for (int i=a;i<= (b); i++) - #defineCLR (a) memset (A,0,sizeof (a)) -typedefLong Longll; -typedef unsignedLong Longull; + using namespacestd; - intReadint () { + intt=0, f=1;CharC=GetChar (); A while(!IsDigit (c)) { at if(c=='-') f=-1; -C=GetChar (); - } - while(IsDigit (c)) { -T= (t<<3) + (t<<1) +c-'0'; -C=GetChar (); in } - returnt*F; to } + Const intmaxn=100009, maxm=200009; - structedge{ the intv; *edge*Next; $}e[maxm],*pt=e,*FIR[MAXN];Panax Notoginseng intN,M,ANS,DFSTIME,SCCCNT,SIZE[MAXN],PRE[MAXN],LOW[MAXN],SCC[MAXN]; - BOOLP[MAXN]; the voidAddintUintv) { +pt->v=v;pt->next=Fir[u]; Afir[u]=pt++; the } + voidAddedge (intUintv) { - Add (u,v); add (v,u); $ } $stack<int>S; - voidDfsintXintf) { - intson=0; thepre[x]=low[x]=++Dfstime; S.push (x); - for(Edge*e=fir[x];e;e=e->next)if(e->v!=f) {Wuyi if(!pre[e->v]) { theson++;d FS (e->v,x); -Low[x]=min (low[x],low[e->v]); Wu if(f!=-1&&LOW[E->V]>=PRE[X]) p[x]=1; -}Else if(!scc[e->v]) low[x]=min (low[x],pre[e->v]); About } $ if(f==-1&&son>1)if(!p[x]) p[x]=1; - if(pre[x]==Low[x]) { - intt=-1;++scccnt; - while(t!=x) { At=S.top (); S.pop (); +scc[t]=scccnt;size[scccnt]++; the } - } $ } the voidTarjan () { theRep (I,1, N)if(!scc[i]) DFS (i,-1); theRep (I,1, N)if(P[i]) ans++; thecout<<ans<<Endl; -Rep (I,1, N)if(P[i]) { inans--;p rintf ("%d", i); thePutchar (ans?)' ':'\ n'); the } About } the intMain () { the //freopen ("#input. txt", "R", stdin); the //freopen ("#output. txt", "w", stdout); +N=readint (); m=readint (); -Rep (I,1, M) { the intU=readint (), v=readint ();Bayi Addedge (u,v); the } the Tarjan (); - //fclose (stdin); - //fclose (stdout); the return 0; the}View Code
Tarjan components and cutting points of strong unicom