标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10207 | Accepted: 4744 |
Description
Input
Output
Sample Input
5 5 1 2 3 4 0 6 2 1 3 5 4 6 2 0 0
Sample Output
1 2
Hint
Source
1 //无向图的割点 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<iostream> 7 #include<queue> 8 #include<vector> 9 #include<stack> 10 using namespace std; 11 const int maxn=107; 12 int n; 13 vector<int> G[maxn]; 14 int ans,low[maxn],pre[maxn],sum,root; 15 bool iscut[maxn]; 16 void dfs(int u,int fa) 17 { 18 int lowu; 19 low[u]=pre[u]=sum++; 20 int l=G[u].size(); 21 int child=0; 22 for(int i=0;i<l;i++) 23 { 24 int v=G[u][i]; 25 if(!pre[v]){ 26 child++; 27 dfs(v,u); 28 low[u]=min(low[u],low[v]); 29 if(u==root&&child==2) iscut[u]=1; 30 if(low[v]>=pre[u]&&u!=root){ 31 iscut[u]=1; 32 } 33 } 34 else if(u!=v) 35 { 36 low[u]=min(low[u],pre[v]); 37 } 38 } 39 } 40 int main() 41 { 42 char c;int m,a,b; 43 while(1){ 44 scanf("%d",&n); 45 if(n==0) break; 46 for(int i=0;i<maxn;i++) G[i].clear(); 47 while(1){ 48 scanf("%d",&m); 49 if(m==0) break; 50 while((c=getchar())!=‘\n‘) 51 { 52 scanf("%d",&b); 53 G[m].push_back(b); 54 G[b].push_back(m); 55 } 56 } 57 memset(pre,0,sizeof(pre)); 58 memset(iscut,0,sizeof(iscut)); 59 memset(low,0,sizeof(low)); 60 ans=0,sum=1,root=1; 61 if(n==1||n==2){printf("0\n");continue;} 62 dfs(1,-1); 63 for(int i=0;i<=n;i++) if(iscut[i]) ans++; 64 printf("%d\n",ans); 65 } 66 }
标签:
原文地址:http://www.cnblogs.com/codeyuan/p/4381714.html