//1.联通图 2.顶点度数都为偶数 ,则存在欧拉回路。 # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int father[1010]; int vis[1010][1010],du[1010]; int find(int x) { if(father[x]==x) return x; return father[x]=find(father[x]); } int main() { int n,m,i,a,b,cot; while(~scanf("%d",&n),n) { for(i=1;i<=n;i++) father[i]=i; scanf("%d",&m); memset(vis,0,sizeof(vis)); memset(du,0,sizeof(du)); while(m--) { scanf("%d%d",&a,&b); if(!vis[a][b]) { if(a>b) swap(a,b);//小的前面,保证父亲节点为最小的那个 vis[a][b]=vis[b][a]=1; du[a]++; du[b]++; int fa=find(a); int fb=find(b); if(fa!=fb) { father[fb]=fa; } } } cot=0; for(i=1;i<=n;i++) { if(du[i]%2==0&&find(i)==1) { cot++; } } if(cot==n) printf("1\n"); else printf("0\n"); } return 0; }
hdu 1878 欧拉回路 (欧拉回路),布布扣,bubuko.com
原文地址:http://blog.csdn.net/lp_opai/article/details/38467399