POJ1144:
Template problem, but the way of input really really is very very egg ache ... Remember ...
1#include <cstdio>2#include <vector>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 #defineRep (i,n) for (int i=1;i<=n;i++)8 #defineCLR (x,c) memset (x,c,sizeof (x))9 Const intnmax= the;Ten intDfn[nmax],low[nmax],iscut[nmax],n,dfn_clock; Onevector<int>F[nmax]; A int Get(Char*ch) { - intx=0; - for(intI=0; ch[i];i++) thex=x*Ten+ch[i]-'0'; - returnx; - } - intDfsintUintFA) { +low[u]=dfn[u]=++Dfn_clock; - intChild=0; + for(intI=0; I<f[u].size (); i++){ A intv=F[u][i]; at if(!Dfn[v]) { -child++; - DFS (v,u); -low[u]=min (low[u],low[v]); - if(low[v]>=Dfn[u]) -iscut[u]=1; in } - Else if(dfn[v]<dfn[u]&&v!=FA) tolow[u]=min (low[u],dfn[v]); + } - if(fa<0&&child==1) iscut[u]=0; the returnLow[u]; * $ }Panax Notoginseng intMain () { - while(SCANF ("%d", &n) &&N) { thedfn_clock=0; +CLR (DFN,0); CLR (Iscut,0); A Rep (I,n) f[i].clear (); the Charch[Ten]; + while(SCANF ("%s", ch) = =1){ - if(ch[0]=='0') Break; $ intu=Get(CH); $ while(SCANF ("%s", ch) = =1){ - intv=Get(CH); - F[u].push_back (v); the f[v].push_back (u); - Chart=GetChar ();Wuyi if(t=='\ n') Break; the } - } WuDfs1,-1); - intans=0; About Rep (i,n) $ if(Iscut[i]) -ans++; -printf"%d\n", ans); - } A return 0; +}
The double connected component of cutting top with undirected graph