Title Address: POJ 1144
Cut points. There are two ways to judge whether a point is a cut point:
If u is a cut point, when and only if the following 1 bars are satisfied
1, if u is the root, then you must have more than 1 subtrees tree
2, if you are not the root, then (u,v) for the branch edge, when Low[v]>=dfn[u].
Then according to these two sentences to find a cut point on it.
The code is as follows:
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include < stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include < Set> #include <algorithm>using namespace Std;int head[200], CNT, INDEX1, Ans;int vis[200], low[200], dfn[200], ge [200];struct node{int u, V, next;} edge[2000];void Add (int u, int v) {edge[cnt].v=v; Edge[cnt].next=head[u]; head[u]=cnt++;} void Tarjan (int u, int fa) {int son=0, I; Low[u]=dfn[u]=++index1; Vis[u]=1; for (i=head[u];i!=-1;i=edge[i].next) {int v=edge[i].v; son++; if (!vis[v]) {Tarjan (v,u); Low[u]=min (Low[v],low[u]); if (u==1&&son>1| | dfn[u]<=low[v]&&u!=1) {ge[u]++; }} else if (V!=FA) low[u]=min (Low[u],dfn[v]); }}void init () {memset (head,-1,sizeof (head)); cnt=0; Index1=ans= 0; memset (vis,0,sizeof (VIS)); memset (dfn,0,sizeof (DFN)); memset (Ge,0,sizeof (GE));} int main () {int n, I, J, u, V; while (scanf ("%d", &n)!=eof&&n) {init (); while (scanf ("%d", &u)!=eof&&u) {while (GetChar ()! = ' \ n ') {scanf ("%d ", &v); Add (U,V); Add (V,u); }} Tarjan (1,-1); for (i=1;i<=n;i++) {if (ge[i]) ans++; } printf ("%d\n", ans); } return 0;}
POJ 1144 Network (strong connected components for cutting points)