And outputs the bridging request tarjan
#include <cstdio> #include <CString> #include <algorithm> #include <Vector> the using namespace STD; const int MAXN = 10010 ; int n-, m, X, Y, index_, DFN [MAXN], Low [MAXN] , ANS, a; // index_ representing the current timestamp Vector < int > G [MAXN]; // save data structure side: adjacency table struct edge { int from , to;} edge [MAXN]; // answers side, and finally we need to sort BOOL CMP ( const edge a, const edge B) { IF (a. from ! = B. from) Return A. From <B. From ; return a.to <b.to;} // comparison function answers sides inline void add_edge member ( int X, int . Y) {Edge [ANS] from = min (X, Y ); edge [ANS] .to = max (X, Y); ANS ++;} // Add to one side in the answer void DFS ( int CUR, int FA) // CUR is the current node, fa his father { int Child; DFN [CUR] = index_ ++; // calculate the current node timestamp Low [CUR] = DFN [CUR]; // currently accessible to the earliest time stamp is certainly its own time stamp for ( intI = 0 ; I <G [cur] .size (); I ++) // loop through all the points cur of { Child = G [cur] [I]; IF ! (DFN [Child] && Child = FA) Low [cur ] = min (low [CUR], DFN [Child]); // if the access to the node is not the parent node, updating low value IF (! DFN [Child]) // if this node is not accessible through the prior { DFS (Child, CUR); // once during dfs IF (DFN [CUR] <Low [Child]) add_edge member (CUR, Child); // if the condition is satisfied, the answer to this edge join sequences low [cur] = min (low [CUR], low [Child]); // update the low value } } } int main () { Scanf (" % D% D " , & n-, & m); for ( int I = 0 ; I <m; I ++) Scanf ( " % D% D " , & X, & Y), G [X] .push_back (Y) , G [Y] .push_back (X); for ( int I = . 1 ; I <= n-; I ++) IF DFS (I, I) (DFN [I]!); // FIG communication may not, initially fa i is the problem does not occur Sort (Edge, Edge + ANS, CMP); // answers row a sequence order for ( int i = 0 ; i <ANS; i ++) the printf ( " % D% D \ n- " , Edge [I]. from , Edge [I] .to); // output return 0; }