booltopo_cmp(constinta,constintb){/* tout[] is obtained by basic dfs */returntout[a]>tout[b];}vector<int>topo_sort(){dfs();vector<int>topo(N);for(inti=0;i<N;i++)topo[i]=i;// sort the vertices by descending order of the "end time" in DFSsort(topo.begin(),topo.end(),topo_cmp);returntopo;}
intN;vector<int>G[MAXN];// an "undirected graph"inttimer,tin[MAXN],low[MAXN];boolvis[MAXN];voidis_bridge(intu,intv){}voiddfs(intv,intparent=-1){vis[v]=true;tin[v]=low[v]=timer++;for(intto:G[v]){if(to==parent)continue;if(vis[to]){// back edgelow[v]=min(low[v],tin[to]);}else{// tree edgedfs(to,v);low[v]=min(low[v],low[to]);if(low[to]>tin[v])is_bridge(v,to);}}}voidfind_bridges(){timer=0;fill(vis,vis+N,false);for(inti=0;i<N;++i)if(!vis[i])dfs(i);}