#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < Stack> #include <vector>using namespace std; #define MAXN 7500#define inf 0x3f3f3f3fint n,m;int G[MAXN][MAXN]; int Clock;int low[maxn],pre[maxn];stack<int>s;int bc;vector<int>bcc[maxn];int dfs (int u,int fa) {low[u]=p Re[u]=++clock; S.push (U); for (int v=1;v<=n;v++) {if (!g[u][v]) continue; if (!pre[v]) {int Lowv=dfs (V,U); Low[u]=min (LOW[U],LOWV); if (Lowv>=pre[u]) {bc++; Bcc[bc].clear (); int tmp=-1; while (!s.empty ()) {tmp=s.top (); S.pop (); Bcc[bc].push_back (TMP); if (tmp==u) break; } if (tmp!=-1) S.push (TMP); Cut the top to add back, arbitrarily cut the top is at least two different two components of the common point}} else if (pre[v]<pre[u]&&fa!=v) {low[u]=min ( LOW[U],PRE[V]); }} return low[u];} void Inital () {clock=0; bc=0; memset (pre,0,sizeof Pre); memset (low,inf,sizeof low); while (!s.empty ()) {s.pop (); }}int Main () {int u,v; Freopen ("In.txt", "R", stdin); while (~SCANF ("%d%d", &n,&m)) {inital (); for (int i=0;i<m;i++) {scanf ("%d%d", &u,&v); G[u][v]=g[v][u]=1; } for (int i=1;i<=n;i++) {if (!pre[i]) DFS (I,-1); } for (int i=1;i<=n;i++) {printf ("%d%d\n", pre[i],low[i]); } printf ("Below is the point Unicom component%d:\n", BC); for (int i=1;i<=bc;i++) {printf ("%d:", i); for (int j=0;j<bcc[i].size (); j + +) {printf ("%d", bcc[i][j]); } printf ("\ n"); } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Dual connected components of undirected graphs (tarjan template)