The number of bridge edges is not shown, and the bridge edge is output according to the problem input sequence.
Note the correspondence between the brig and the edges.
#include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio > #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map > #define INF 0x3f3f3f3f#pragma COMMENT (linker, "/stack:16777216") #define EPS 1e-6#define ll long longusing namespace s TD; #define M 200003#define N 10003int head[n],num,dfn[n],low[n],n,m,idx,brig[m<<1],bum;struct edge{int St,ed,ne XT;} E[m<<1];void addedge (int x,int y) {e[num].st=x; E[num].ed=y; E[NUM].NEXT=HEAD[X]; head[x]=num++;} void Tarjan (int u,int father) {int i,v; low[u]=dfn[u]=idx++; for (I=head[u];i!=-1;i=e[i].next) {V=e[i].ed; if (v==father) continue; if (dfn[v]==-1) {Tarjan (v,u); low[u]=low[u]>low[v]?low[v]:low[u]; if (Low[v]>dfn[u])//bum bridge corresponding to the side of the number brig[bum++]=i; } else low[u]=low[u]>dfn[v]?dfn[v]:low[u]; }}void INIT () {memset (dfn,-1,sizeof DFN); memset (head,-1,sizeof head); num=bum=idx=0;} String hash[n];string s1,s2;bool cmp (int a,int b) {return a<b;} int main () {int icy,i,cnt; scanf ("%d", &icy); while (icy--) {scanf ("%d%d", &n,&m); Init (); Map<string,int> MP; Cnt=1; for (i=0;i<m;i++) {cin>>s1>>s2; if (!mp[s1]) hash[cnt]=s1,mp[s1]=cnt++; if (!mp[s2]) hash[cnt]=s2,mp[s2]=cnt++; Addedge (Mp[s1],mp[s2]); Addedge (Mp[s2],mp[s1]); } Tarjan (1,-1); for (i=1;i<=n;i++)//judgment diagram not connected if (dfn[i]==-1) break; if (i<=n) {printf ("0\n"); Continue } printf ("%d\n", bum); Sort (brig,brig+bum,cmp); for (int j=0;j<bum;j++) {i=brig[j]; if (i&1) i--; cout<