//http://acm.hdu.edu.cn/showproblem.php?pid=1878
ac代码:
#include<iostream> #include<cstdio> #include<queue> using namespace std; queue<int>q; int n; int indegree[1001]; int a[1001][1001]; int panduan() { int i; for (i=1;i<=n;i++) if (indegree[i]%2) return 1; return 0; } int bfs() { int vis[1001]; int i,j,temp; q.push(1); for (i=1;i<=n;i++) vis[i]=0; while(!q.empty()) { temp=q.front(); q.pop(); for (i=1;i<=n;i++) if ((a[temp][i])&&(!vis[i])) { vis[i]=1; q.push(i); } } for (i=1;i<=n;i++) if (vis[i]==0) return 0; return 1; } int main() { int m,c,d,i,j; while(scanf("%d%d",&n,&m)==2) { for (i=1;i<=n;i++) indegree[i]=0; for (i=1;i<=n;i++) for (j=1;j<=n;j++) a[i][j]=0; for (i=1;i<=m;i++) { scanf("%d%d",&c,&d); a[c][d]=1; a[d][c]=1; indegree[c]++; indegree[d]++; } if (panduan()) printf("0\n"); else if (bfs()) printf("1\n"); else printf("0\n"); } return 0; }