POJ 1144 割点
题意 :求割点的数量
1 #include<iostream> 2 #include<stdio.h> 3 #include<vector> 4 #include<string.h> 5 #include<stdlib.h> 6 using namespace std; 7 const int maxn = 1e5+10; 8 int dfn[maxn], low[maxn]; 9 int cut[maxn]; 10 int n,m,num,sol; 11 vector<int> g[maxn]; 12 void init() 13 { 14 memset(dfn,0,sizeof(dfn)); 15 memset(cut,0,sizeof(cut)); 16 for(int i=0;i<=n;i++) g[i].clear(); 17 num=sol=0; 18 } 19 void tarjan(int u,int fa) 20 { 21 int children = 0; 22 dfn[u] = low[u] = ++num; 23 for (int i=0;i<g[u].size();i++) 24 { 25 int v=g[u][i]; 26 if (!dfn[v]) 27 { 28 children++; 29 tarjan(v,u); 30 low[u] = min(low[u], low[v]); 31 if ((fa == -1 && children >= 2)||(fa != -1 && low[v] >= dfn[u])) 32 cut[u]=1; 33 } 34 else if (v != fa) 35 low[u] = min(low[u], dfn[v]); 36 } 37 } 38 int main() 39 { 40 while(scanf("%d",&n)!=EOF&&n) 41 { 42 int x,y; 43 init(); 44 while(scanf("%d",&x)&&x) 45 { 46 while(getchar()!='\n') 47 { 48 scanf("%d",&y); 49 g[x].push_back(y); 50 g[y].push_back(x); 51 } 52 } 53 tarjan(1,-1); 54 for(int i=0;i<=n;i++) 55 if(cut[i])sol++; 56 printf("%d\n",sol); 57 } 58 }