#include<cstdio> #include<vector> #include<cstring> #include<cstdlib> using namespace std; vector<int>path[200]; bool visite[200]; int n; int iscritical(int off) { for(int i=1;i<=n;i++) { if(visite[i]==false&&i!=off)return 1; } return 0; } void dfs(int source,int off) { visite[source]=true; for(int i=0;i<path[source].size();i++) { int a=path[source][i]; if(visite[a]==false&&a!=off)dfs(a,off); } } int main() { char a[1000],*p; while(gets(a)!=NULL) { n=atoi(a); if(n==0)break; while(gets(a)) { p=strtok(a," \n"); int s=atoi(p); if(s==0)break; p=strtok(NULL," \n"); while(p!=NULL) { int m=atoi(p); path[s].push_back(m); path[m].push_back(s); p=strtok(NULL," \n"); } } if ( n == 1 ) { printf ("0\n"); continue; } int critical=0; memset(visite,false,sizeof(visite)); dfs(2,1); critical=critical+iscritical(1); for(int i=2;i<=n;i++) { memset(visite,false,sizeof(visite)); dfs(1,i); critical=critical+iscritical(i); } printf("%d\n",critical); for(int i=1;i<200;i++)path[i].clear(); } }
Sunday, August 17, 2014
uva : 315 - Network
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment