Test instructions
Give a diagram some side, ensure the diagram is connected
Q for each edge, if the edge is removed, some points in the graph are not connected. These points (U,V) are required to make you as small as possible, V as large as possible, and output such (U,V). Otherwise output 0 0.
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN = 1e5 +1;4typedef pair <int,int>PII;5Vector<pii>G[MAXN];6 BOOLISBRIDGE[MAXN];7 intCLK, PRE[MAXN], LOW[MAXN];8 intIDX, MAXV[MAXN], NEWIDX[MAXN], NEWMAX[MAXN];9 intU[MAXN], V[MAXN];Ten intANS[MAXN]; One BOOLVIS[MAXN]; A intN, M; - - voidinit () { thememset (Isbridge,false,sizeof(Isbridge));//Record Bridge -memset (PRE,0,sizeof(pre));//timestamp of the first access recorded -memset (Low,0,sizeof(low));//The pre value of the earliest ancestor that itself and its child nodes can return to -CLK =0;//time Stamp + for(inti =0; i < MAXN; i++) { - g[i].clear (); + } A } at - voidDFS (intUintPA) { - intLowu = Pre[u] = + +CLK; - for(inti =0; I < g[u].size (); i++) { -PII e =G[u][i]; - intv =E.first; in intIDX =E.second; - if(!Pre[v]) { to DFS (V, u); +Lowu =min (Lowu, low[v]); - if(Low[v] >Pre[u]) { theISBRIDGE[IDX] =true; * } $}Else if(Pre[v] < Pre[u] && v! =PA) {Panax Notoginseng //is the reverse edge update Lowu -Lowu =min (Lowu, pre[v]); the } + } ALow[u] = Lowu;//Change Low[u] the } + - voidDFS2 (intUintPA) { $Vis[u] =true; $Maxv[u] =u; -Newidx[u] =IDX; - for(inti =0; I < g[u].size (); i++) { thePII e =G[u][i]; - intv =E.first;Wuyi intIDX =E.second; the if(!isbridge[idx] && v! = PA &&!Vis[v]) { - DFS2 (V, u); WuMaxv[u] =Max (Maxv[u], maxv[v]); - } About } $ } - - voidBcc_bridge () { -DFS (1, -1);//Record Bridge Amemset (Vis,false,sizeof(Vis)); +IDX =0; the for(inti =1; I <= N; i++) { - if(!Vis[i]) { $idx++; theDFS2 (I,-1);//Pinch point the } the } the //re-record the indented point - for(inti =1; I <= N; i++) { in g[i].clear (); the } the for(inti =0; I < m; i++) { About if(Isbridge[i]) { the intU = newidx[u[i]], V =Newidx[v[i]]; the G[u].push_back (Make_pair (v, i)); the G[v].push_back (Make_pair (U, i)); + } - } the }Bayi the voidSolve (intUintPA) { thePre[u] = + +CLK; -Ans[u] =Newmax[u]; - for(inti =0; I < g[u].size (); i++) { the intv =G[u][i].first; the if(V! =PA) { the Solve (V, u); theAns[u] =Max (Ans[u], ans[v]); - } the } the } the 94 intMain () { the intT; thescanf ("%d", &T); the while(t--) {98Init ();//to initialize Aboutscanf ("%d%d", &n, &m); - for(inti =0; I < m; i++) {101 intu, v;102scanf ("%d%d", &u, &v);103U[i] = u, v[i] =v;104 G[u].push_back (Make_pair (v, i)); the G[v].push_back (Make_pair (U, i));106 }107 Bcc_bridge ();108 for(inti =1; I <= N; i++) {109Newmax[newidx[i]] =Maxv[i]; the }111 intu; the for(U =1; U <= N; u++) {113 if(Newmax[u] = =N) { the Break; the } the }117memset (PRE,0,sizeofpre);118CLK =0;//Redefining timestamps119Solve (U,0); - for(inti =0; I < m; i++) {121 intU = newidx[u[i]], V =Newidx[v[i]];122 if(U = =v) {123printf"0 0\n");124}Else { the if(Pre[u] <Pre[v]) {126 swap (U, v);127 } -printf"%d%d\n", Ans[u], ans[u]+1);129 } the }131 } the return 0;133}
Hdu 5409 CRB and Graph (side double Unicom component)