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 38 39 40 41 42
| void dfs(int x,int ef) { f[x]=true; low[x]=d[x]=++Time; sta.push(x); for (int e=head[x];e!=-1;e=nxt[e]) { if (e==(ef^1)) continue; if (!f[vet[e]]) { dfs(vet[e],e); low[x]=min(low[x],low[vet[e]]); } else low[x]=min(low[x],d[vet[e]]); } if (low[x]==d[x]) { idnum++; while (sta.top()!=x) { idx[sta.top()]=idnum; sta.pop(); } idx[x]=idnum; sta.pop(); } } int main() { num=-1; memset(head,-1,sizeof(head)); int n,m; cin >> n >> m; for (int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); addedge(x,y); addedge(y,x); } for (int i=1;i<=n;i++) if (!f[i]) dfs(i,-1); for (int i=0;i<m;i++) { int u=idx[vet[i<<1]],v=idx[vet[i<<1|1]]; if (u!=v) deg[u]++,deg[v]++; } return 0; }
|