# HDU1878 欧拉回路

2018-03-01 12:21:50来源:cnblogs.com作者:自为风月马前卒人点击

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16701    Accepted Submission(s): 6457

## Sample Input

3 31 21 32 33 21 22 30

10

ZJU

## Recommend

判断欧拉回路的重要条件：所有点的度数均为偶数然后并查集判断当成功次数>=点数-1时说明存在
`#include<cstdio>#include<cstring>const int MAXN=1e6+10;inline int read(){    char c=getchar();int x=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}    return x*f;}int N,M;int fa[MAXN],inder[MAXN];int find(int x){    if(fa[x]==x) return fa[x];    else return fa[x]=find(fa[x]);}int unionn(int x,int y){    int fx=find(x);    int fy=find(y);    if(fx==fy) return 0;    fa[fx]=fy;    return 1;}int main(){    while(scanf("%d",&N)&&N)    {        if(N==0) break;        memset(inder,0,sizeof(inder));        int ans=0;        for(int i=1;i<=N;i++) fa[i]=i;        scanf("%d",&M);        for(int i=1;i<=M;i++)        {            int x=read(),y=read();            inder[x]++;inder[y]++;            ans+=unionn(x,y);        }        bool flag=1;        if(ans<N-1) {flag=0;printf("0/n");continue;}        for(int i=1;i<=N;i++)            if(inder[i]&1)                {flag=0;printf("0/n");break;}        if(flag) printf("1/n");    }    return 0;}`