zoukankan      html  css  js  c++  java
  • UVA 10196 Morning Walk(欧拉回路)

    Problem H

    Morning Walk

    Time Limit

    3 Seconds

    Kamalis a Motashotaguy. He has got a new job in Chittagong. So, he has moved to Chittagong fromDinajpur. He was getting fatter in Dinajpur as he had no work in his hand there. So, moving toChittagong has turned to be a blessing for him. Every morning he takes a walk through the hilly roads of charming city Chittagong. He is enjoying this city very much. There are so many roads in Chittagongand every morning he takes different paths for his walking. But while choosing a path he makes sure he does not visit a road twice not even in his way back home. An intersection point of a road is not considered as the part of the road. In a sunny morning, he was thinking about how it would be if he could visit all the roads of the city in a single walk. Your task is to help Kamal in determining whether it is possible for him or not.

    Input

    Input will consist of several test cases. Each test case will start with a line containing two numbers. The first number indicates the number of road intersections and is denoted byN(2 ≤ N ≤ 200). The road intersections are assumed to be numbered from0 to N-1. The second numberR denotes the number of roads (0 ≤ R ≤ 10000). Then there will beRlines each containing two numbersc1 andc2indicating the intersections connecting a road.

    Output

    Print a single line containing the text “Possible” without quotes if it is possible for Kamal to visit all the roads exactly once in a single walk otherwise print “Not Possible”.

    Sample Input

    Output for Sample Input

    2 2

    0 1

    1 0

    2 1

    0 1

    Possible

    Not Possible


    WA了一个上午。最终找出错误了,visit all the roads of the city in a single walk.走全然部的边且每条边仅仅走一次,点能够不走完,一直WA在这里。

    题意:给出N个点和R条边,问能不能走全然部的边且每条边仅仅走一次,点能够不走完。

    deg记录每一个点的度,并查集推断全部的边和这些边连接的点是不是一个连通图。

    #include<stdio.h>
    #include<string.h>
    int father[205], deg[205];
    
    int Find(int x)
    {
        if(x != father[x])
            father[x] = Find(father[x]);
        return father[x];
    }
    
    void Init(int n)
    {
        memset(deg, 0, sizeof(deg));
        for(int i = 0; i < n; i++)
            father[i] = i;
    }
    
    int main()
    {
        int n, r,i;
        while(scanf("%d%d",&n,&r)!=EOF)
        {
            if(r == 0)
            {
                printf("Not Possible
    ");
                continue;
            }
            Init(n);
            int u, v;
            for(i = 0; i < r ; i++)
            {
                scanf("%d%d",&u,&v);
                father[Find(u)] = Find(v);
                deg[u]++;
                deg[v]++;
            }
            int ok = 1;
            int j = 0;
            while(deg[j] == 0)
                j++;
            for(i = j + 1; i < n; i++)
                if(deg[i] && Find(i) != Find(j))
                {
                    ok = 0;
                    break;
                }
            int cnt = 0;
            for(i = 0; i < n; i++)
                if(deg[i] % 2 != 0)
                    cnt++;
            if(!ok || cnt > 0)
                printf("Not Possible
    ");
            else
                printf("Possible
    ");
        }
        return 0;
    }



  • 相关阅读:
    centos7 rc.local 开机不执行
    springboot与tomcat中GZip压缩
    使用Nginx对Websocket进行反向代理
    spring-data-redis 关于订阅客户端不断创建新线程的问题
    使用apache.tika判断文件类型
    简单理解TCP通信的三次握手
    logback异步输出日志(生产者消费者模型),并非批量写入日志。
    将文本(lrc,txt)文件转换成UTF-8格式
    docker入门(三)
    Spring session(redis存储方式)监听导致创建大量redisMessageListenerContailner-X线程
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6924953.html
Copyright © 2011-2022 走看看