1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| void dfs(int x,int ef) { int son=0; f[x]=true; low[x]=d[x]=++Time; for (int e=head[x];e!=-1;e=next[e]) { if (e==(ef^1)) continue; if (!f[vet[e]]) { dfs(vet[e],e); low[x]=min(low[x],low[vet[e]]); if (x!=root && d[x]<=low[vet[e]]) cut[x]++; if (low[vet[e]]>d[x]) bridge[e/2]=true; son++; } else low[x]=min(low[x],d[vet[e]]); } if (x==root && son>1) cut[x]=son-1; }
num=-1; memset(head,-1,sizeof(head)); for (int i=1;i<=n;i++) if (!f[i]) { root=i; dfs(i,-1); } for (int i=1;i<=n;i++) if (cut[i]!=0) cout<< i << " " << cut[i]+1 << endl; for (int i=0;m>i;i++) if (bridge[i]) cout<< vet[i*2] << " " << vet[i*2+1] << endl;
|