Topic links
Test Instructions: The number of cut points is given by a graph without direction .
Ideas: very naked topic, direct template can be.
code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int MAXN = 1005;struct edge{int to, next; bool Cut;} EDGE[MAXN * 10];int HEAD[MAXN], Tot;int LOW[MAXN], dfn[maxn];int Index, Cnt;bool cut[maxn];void addedge (int u, int v) { Edge[tot].to = v; Edge[tot].next = Head[u]; Edge[tot].cut = false; Head[u] = tot++;} void Tarjan (int u, int pre) {int V; Low[u] = dfn[u] = ++index; int son = 0; for (int i = head[u]; I! =-1; i = edge[i].next) {v = edge[i].to; if (v = = pre) continue; if (! Dfn[v]) {son++; Tarjan (V, u); if (Low[u] > Low[v]) low[u] = Low[v]; if (u! = Pre && low[v] >= Dfn[u]) {Cut[u] = true; }} else if (Low[u] > Dfn[v]) low[u] = Dfn[v]; } if (U = = Pre && son > 1) cut[u] = true;} void Init () {memset (head,-1, sizeof (head));memset (DFN, 0, sizeof (DFN)); Memset (cut, false, sizeof (cut)); tot = 0; Index = CNT = 0;} int main () {int n; while (scanf ("%d", &n) && N) {init (); int u, v; while (scanf ("%d", &u) && u) {char ch; while (scanf ("%d%c", &v, &ch)) {Addedge (U, v); Addedge (V, u); if (ch = = ' \ n ') break; }} for (int i = 1; I <= n; i++) if (! Dfn[i]) Tarjan (i, I); for (int i = 1; I <= n; i++) if (cut[i]) cnt++; printf ("%d\n", CNT); } return 0;}
Uva315-network (non-direction graph cut point)