10596 - Morning Walk//欧拉回路

来源:互联网 发布:php图片验证码源码 编辑:程序博客网 时间:2024/05/21 14:05
/*The describe is not clear*/#include<cstdio>#include<cstring>using namespace std;const int maxn = 205;int degree[maxn];int f[maxn];int N,R;int find(int x){    if(x != f[x])    {        f[x] = find(f[x]);    }    return f[x];}int main(){    while(scanf("%d%d",&N,&R)!=EOF)    {        if(R ==0 )        {            printf("Not Possible\n");            continue;        }        //initilize        memset(degree,0,sizeof(degree));        for(int i = 0;i <= N;i++) f[i] = i;        //make a graph and record the degrees        for(int i = 0;i < R;i++)        {            int a,b;            scanf("%d%d",&a,&b);            degree[a]++;            degree[b]++;            if(find(a) != find(b)) f[find(a)] = find(b);        }        //judge whether the graph is conneted        bool ok = true;        int j = 0;        for(j = 0;!degree[j];j++)        for(int i = j + 1;i < N;i++)        {            if(degree[i] && find(j) != find(i))            {                ok = true;                break;            }        }        if(ok)        {            for(int i = 0;i < N;i++)            {                if(degree[i]%2)                {                    ok = false;                    break;                }            }        }        if(ok) printf("Possible\n");        else printf("Not Possible\n");    }    return 0;}

原创粉丝点击