#include <iostream>#include<cstdio>#include<cstring>#include<queue>#include<vector>#include<stack>#include<algorithm>#include<cmath>#defineMem (A, B) memset (A, B, sizeof (a))using namespacestd;Const intMAXN =10010, INF =0x7fffffff;intPRE[MAXN], LOW[MAXN], ISCUT[MAXN];intDfs_clock, N, Cnt;vector<int>G[MAXN];structedge{intu, v;} EDGE[MAXN];intCMP (Edge A, Edge b) {if(a.u = = b.u)returnA.V <B.V; returnA.u <b.u;}intDfsintUintFA) { intLowu = Pre[u] = + +Dfs_clock; intChild =0; for(intI=0; I<g[u].size (); i++) { intv =G[u][i]; if(!Pre[v]) { Child++; intLOWV =Dfs (v, u); Lowu=min (Lowu, LOWV); if(Lowv >Pre[u]) {Iscut[u]=1; EDGE[CNT].U= u, edge[cnt].v =v; if(Edge[cnt].u >edge[cnt].v) Swap (edge[cnt].u, EDGE[CNT].V); CNT++; } } Else if(Pre[v] < Pre[u] && v! =FA) Lowu=min (Lowu, pre[v]); } if(FA <0&& Child = =1) Iscut[u] =0; Low[u]=Lowu; returnLowu;}voidinit () {CNT=0; Dfs_clock=0; MEM (PRE,0); Mem (Low,0); Mem (Iscut,0); for(intI=0; i<=n; i++) G[i].clear ();}intMain () { while(cin>>N) {init (); for(intI=0; i<n; i++) { intu, D, v; scanf ("%d (%d)", &u, &d); for(intI=0; i<d; i++) {cin>>v; G[u].push_back (v); G[v].push_back (U); } } for(intI=0; i<n; i++) if(!Pre[i]) DFS (i,-1); Sort (edge, Edge+CNT, CMP); printf ("%d critical links\n", CNT); for(intI=0; i<cnt; i++) cout<< edge[i].u <<" - "<< EDGE[I].V <<Endl; cout<<Endl; } return 0;}
Network POJ-3694 (connect icon for bridge)