1, Judge cut the top:
For the root node, of course, it is simple, and only if it has two or more child nodes, he is the cutting top.
For other nodes,
Theorem: In a Dfs tree with undirected graphs connected to figure g, the non-root node u is the top of the G and only if U exists a sub-node V, so that V and all its descendants have no reverse edge to connect back to the ancestor of U
#include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include < cstring> #include <stack> #include <vector> #include <queue> #include <map> using namespace St
D
const int MAXN = 1000;
Vector<int> G[MAXN]; int PRE[MAXN], dfs_clock, LOW[MAXN], N; Accesses the order flag of the current point, Dfs_clock represents the timestamp, Low[v] is the pre-value of the earliest ancestor that V and its descendants can practice (bool ISCUT[MAXN];
is the cut-top void init () {for (int i=0; i<n; i++) g[i].clear ();
Memset (Iscut, False, sizeof (iscut));
memset (pre, 0, sizeof (pre));
Dfs_clock = 0;
} int Dfs (int u, int fa)//u the parent node in the Dfs tree is FA returns the minimum low of u {int Lowu = pre[u] = ++dfs_clock; int child = 0;
The number of child nodes for (int i=0; i<g[u].size (); i++) {int v = g[u][i];
if (!pre[v])//has not visited V, it is not necessary to mark the {child++ with Vis; int LOWV = DFS (v, u);
Gets the child node minimum low if (LOWV >= pre[u]) iscut[u] = true; Lowu = min (Lowu, LOWV); Update with the low function of the descendant The Low function of U} else if (Pre[v] < Pre[u] && v! = FA)//(U,V) for reverse Edge Lowu = min (Lowu, PRE[V]); Update the low function of U with reverse edge} if (FA < 0 && Child < 2)//root node when and only if it has two or more sub-nodes is the top cut iscut[u] = Fals
E
Low[u] = Lowu;
return LOWU;
} int main () {int m, u, v;
scanf ("%d%d", &n, &m);
Init ();
for (int i=0; i<m; i++) {cin>>u>>v;
G[u].push_back (v);
G[v].push_back (U);
} for (int i=0; i<n; i++) if (!pre[i]) DFS (i,-1);
for (int i=0; i<n; i++)//Cut point output if (Iscut[i]) printf ("%d", I);
Putchar (' \ n ');
return 0;
}
Other key charts are based on: links