This problem is actually a very simple cutting edge template problem, but need to deal with the heavy side of the tutor's opinion a little trouble
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace STD;Const intmaxn=20005;Const intmaxm=200005;structedge{intTo,next,id,num;//This place requires an ID (the label of the Edge) and num (whether to be a heavy edge) on the base of the original template. BOOLCut;} EDGE[MAXM];intANS[MAXM];intHead[maxn],tot;intLOW[MAXN],DFN[MAXN],STACK[MAXN];intIndex,top;BOOLINSTACK[MAXN];BOOLCUT[MAXN];intADD_BLOCK[MAXN];intBridgeintT,a,b;Long LongN,m;voidAddedge (intUintVintXintNum//I was right when I passed four values, and I didn't do it when I didn't pass Num.{edge[tot].to=v; Edge[tot].next=head[u]; edge[tot].cut=false; Edge[tot].id=x; Edge[tot].num=num; head[u]=tot++;}voidTarjan (intUintPre) {intv,k=1; Low[u]=dfn[u]=++index; Stack[top++]=u; instack[u]=true;intson=0, sum=0; for(intI=head[u]; i!=-1; I=edge[i].next) {v=edge[i].to;if(V==pre)Continue;if(!dfn[v]) {son++; Tarjan (V,u);if(Low[u]>low[v]) low[u]=low[v];if(low[v]>dfn[u]&&edge[i].num!=1) {bridge++; edge[i].cut=true; edge[i^1].cut=true; Ans[bridge]=edge[i].id;//Here is the label of the side directly} }Else if(Low[u]>dfn[v]) low[u]=dfn[v]; }if(U==pre) add_block[u]=son-1; instack[u]=false; top--;}voidInit () {tot=0; Bridge=0; index=0;memset(Low,0,sizeof(low));memset(DFN,0,sizeof(DFN));memset(Instack,0,sizeof(Instack));memset(Add_block,0,sizeof(Add_block));memset(edge,-1,sizeof(Edge));memset(head,-1,sizeof(head));memset(ANS,0,sizeof(ans));}intMain () {Ios::sync_with_stdio (false);Cin>>T; while(t--) {init ();Cin>>n>>m; for(intI=1; i<=m; i++) {Cin>>a>>b; for(intJ=head[a]; j!=-1; J=edge[j].next)if(edge[j].to==b) {edge[i].num=1; } addedge (A,b,i,edge[i].num); Addedge (B,a,i,edge[i].num); } for(intI=1; i<=n; i++) {Tarjan (i,i); }cout<<bridge<<endl;when processing the output, the first thing to consider is the problem of the output blank line, and then need to consider the time when there is no bridge, eat a great loss here, always wa to dieSort (ans+1, ans+bridge+1); for(intI=1, U=bridge; i<=bridge; i++) {cout<<ans[i];if(--u)cout<<" "; }if(bridge)cout<<endl;ifTcout<<endl; }return 0;}
zoj2588 (non-direction graph for cutting edge)