UVA 10596 (13.07.11)

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 ablessing for him. Every morning he takes a walk through the hilly roads ofcharming city Chittagong. He isenjoying this city very much. There are so many roads in Chittagongand every morning he takes different paths for his walking. But while choosinga path he makes sure he does not visit a road twice not even in his way backhome. An intersection point of a road is not considered as the part of theroad. In a sunny morning, he was thinking about how it would be if he couldvisit 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 severaltest cases. Each test case will start with a line containing two numbers. Thefirst number indicates the number of road intersections and is denoted by N(2 ≤ N ≤ 200). The road intersections are assumed to benumbered from 0 to N-1. The second number R denotes thenumber of roads (0 ≤ R ≤ 10000). Then there will be Rlines each containing two numbers c1 and c2indicating the intersections connecting a road.

 

Output

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

 

Sample Input

Output for Sample Input

2 2

0 1

1 0

2 1

0 1

Possible

Not Possible

 

Problemsetter: MuhammadAbul Hasan

International IslamicUniversity Chittagong


这题的题意有些让人曲解

我的第一反应也是说这是有向图

但是, 这题的有向图可用无向图做

通过查连通 以及 度数是否满足欧拉回路的要求即可~

AC代码如下 :

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int N, R, mark, num;
int map[400][400];
int degree[400];
int vis[400];

void init() {
    num = 1;
    mark = 1;
    memset(degree, 0 ,sizeof(degree));
    memset(vis, 0 ,sizeof(vis));
    for(int i = 0; i < 400; i++)
        for(int j = 0; j < 400; j++)
            map[i][j] = 0;
    for(int i = 1; i <= R ; i++) {
        int begin, end;
        scanf("%d%d", &begin, &end);
        map[begin][end] = 1;
        degree[begin] = degree[begin] + 1;
        degree[end] = degree[end] + 1;
    }
}

void judge_connect(int node) {
    vis[0] = 1;
    for(int i = 0; i < N; i++) {
        if(vis[i] == 0 && map[node][i] == 1) {
            vis[i] = 1;
            ++num;
            judge_connect(i);
        }
    }
}

void judge_degree() {
    for(int i = 0; i < N; i++) {
        if(degree[i] % 2 == 1) {
            mark = 0;
            break;
        }
    }
}

int main() {
    while(scanf("%d%d", &N, &R) != EOF) {
        init();
        judge_connect(0);
        judge_degree();
        if(mark == 1 && num == N && R > 0)
            printf("Possible\n");
        else
            printf("Not Possible\n");
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值