A simple undirected graph is used to calculate the cut point.
The Code is as follows:
# Include <cstdlib> # include <cstring> # include <cstdio> # include <algorithm> # define maxn 1005 using namespace STD; int head [maxn], idx, Lim, dfn [maxn], low [maxn], Ti; int subnet [maxn]; bool vis [maxn]; struct edge {int V, next;} e [maxn * maxn]; void addedge (int x, int v) {++ idx; E [idx]. V = V, E [idx]. next = head [X]; head [x] = idx;} void DFS (int u) {// The lower the low value, the better. For (INT I = head [u]; I! =-1; I = E [I]. Next) {If (! Vis [E [I]. v]) {vis [E [I]. v] = true; dfn [E [I]. v] = low [E [I]. v] = ++ Ti; DFS (E [I]. v); low [u] = min (low [u], low [E [I]. v]); If (low [E [I]. v] = dfn [u]) {// the child does not have any other way to reach the upper layer + + subnet [u];} else {LOW [u] = min (low [u], dfn [E [I]. v]) ;}} void solve () {bool flag = false; memset (VIS, false, sizeof (VIS); memset (subnet, 0, sizeof (subnet); subnet [1] =-1; vis [1] = true; // because Figure 1 is China Unicom, so we can find all the points dfn [1] = low [1] = ++ Ti; DFS (1); For (INT I = 1; I <= lim; ++ I) {If (subnet [I]> 0) {printf ("SPF node % d leaves % d subnets \ n", I, subnet [I] + 1); flag = 1 ;}} if (! Flag) {puts ("No SPF nodes") ;}} int main () {int A, B, CA = 0; bool indata = false, first = true; lim = Ti = 0, idx =-1; memset (Head, 0xff, sizeof (head); While (1) {scanf ("% d", & ); lim = max (Lim, a); If (! A) {If (! Indata) break; else {If (first) {First = false;} else {puts ("") ;}indata = false; printf ("Network # % d \ n ", ++ CA); solve (); Lim = Ti = 0, idx =-1; // an initialized memset (Head, 0xff, sizeof (head); continue ;}} indata = true; scanf ("% d", & B); // indicates that A and B have an undirected edge Lim = max (Lim, B ); // find the largest vertex number addedge (a, B); addedge (B, A); // bidirectional edge of an undirected graph} return 0 ;}