标签:style blog http color os io ar for art
1 //Accepted 1240 KB 250 ms 2 //水题 欧拉回路 3 //连通+节点度均为偶数 4 #include <cstdio> 5 #include <cstring> 6 #include <queue> 7 #include <iostream> 8 using namespace std; 9 const int imax_n = 1005; 10 bool a[imax_n][imax_n]; 11 bool vis[imax_n]; 12 int cnt[imax_n]; 13 int n,m; 14 queue<int >q; 15 16 void bfs(int s) 17 { 18 while (!q.empty()) q.pop(); 19 q.push(s); 20 vis[s]=true; 21 while (!q.empty()) 22 { 23 int x=q.front(); 24 q.pop(); 25 for (int i=1;i<=n;i++) 26 { 27 if (!vis[i] && a[x][i]==true) 28 { 29 vis[i]=true; 30 q.push(i); 31 } 32 } 33 } 34 } 35 int judge() 36 { 37 memset(vis,0,sizeof(vis)); 38 int ans=0; 39 for (int i=1;i<=n;i++) 40 { 41 if (!vis[i]) ans++; 42 if (ans>=2) return 0; 43 bfs(i); 44 } 45 return 1; 46 } 47 int slove() 48 { 49 //printf("judge=%d\n",judge()); 50 if (judge()==0) return 0; 51 for (int i=1;i<=n;i++) 52 { 53 if (cnt[i]%2!=0) return 0; 54 } 55 return 1; 56 } 57 int main() 58 { 59 while (scanf("%d",&n),n) 60 { 61 scanf("%d",&m); 62 memset(cnt,0,sizeof(cnt)); 63 memset(a,false,sizeof(a)); 64 int x,y; 65 for (int i=1;i<=m;i++) 66 { 67 scanf("%d%d",&x,&y); 68 a[x][y]=a[y][x]=true; 69 cnt[x]++; 70 cnt[y]++; 71 } 72 printf("%d\n",slove()); 73 } 74 return 0; 75 }
标签:style blog http color os io ar for art
原文地址:http://www.cnblogs.com/djingjing/p/3954673.html