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\n");
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\n");
else
printf("Possible\n");
}
return 0;
}

UVA 10196 Morning Walk(欧拉回路)的更多相关文章

  1. Uva 10596 - Morning Walk 欧拉回路基础水题 并查集实现

    题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起 ...

  2. UVa 10596 Moring Walk【欧拉回路】

    题意:给出n个点,m条路,问能否走完m条路. 自己做的时候= =三下两下用并查集做了交,WA了一发-后来又WA了好几发--(而且也是判断了连通性的啊) 搜了题解= = 发现是这样的: 因为只要求走完所 ...

  3. uva 10596 - Morning Walk

    Problem H Morning Walk Time Limit 3 Seconds Kamal is a Motashota guy. He has got a new job in Chitta ...

  4. UVA 10054 the necklace 欧拉回路

    有n个珠子,每颗珠子有左右两边两种颜色,颜色有1~50种,问你能不能把这些珠子按照相接的地方颜色相同串成一个环. 可以认为有50个点,用n条边它们相连,问你能不能找出包含所有边的欧拉回路 首先判断是否 ...

  5. UVa 10129单词(欧拉回路)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. UVa 10917 A Walk Through the Forest

    A Walk Through the Forest Time Limit:1000MS  Memory Limit:65536K Total Submit:48 Accepted:15 Descrip ...

  7. uva 10196 Check The Check

    题目:10196 - Check The Check 思路:水题..模拟 这个代码,前半部分是在数统机房上课的时候写的,挫了点,懒得改了. #include <cstdio> #inclu ...

  8. UVa 10054 项链(欧拉回路)

    https://vjudge.net/problem/UVA-10054 题意:有一种由彩色珠子连接成的项链.每个珠子的两半由不同颜色组成.相邻两个珠子在接触的地方颜色相同.现在有一些零碎的珠子,需要 ...

  9. UVA - 10196:Check The Check

    类型:简单模拟 大致题意:已知国际象棋行棋规则,给你一个局面,问是否将军?谁将谁的军?(保证不会同时将军) 思路:都以小写字母 测试 是否将 大写字母. 然后一个局面测两次(一次直接测,一次反转棋盘, ...

随机推荐

  1. oc19--继承1

    // // Phone.h // day13 #import <Foundation/Foundation.h> // 被继承的这个类我们称之为父类/ 超类 @interface Phon ...

  2. ubuntu的home目录下,Desktop等目录消失不见

    第一步:创建相应的文件夹 首先当然是创建几个相应的英文文件夹喽,比如:Desktop.Downloads. Documents. Music. Pictures. Videos  , Template ...

  3. SVO在ROS下的配置与运行

    最近在做实验的时候,需要配置SVO,下面讲讲其中的过程以及遇到的问题: 首先说明配置环境:Ubuntu 14.04 + ROS indigo,ROS的安装我参考了ROS的官网上给出的教程:http:/ ...

  4. 外观模式(Facade)C++实现

    外观模式 意图: 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一系统更加容易使用. 适用性: 1.在设计初期阶段,应该要有意识的将不同的两个层分离,比如经典的三层架 ...

  5. 第六课: - GroupBy函数

    第 6 课   让我们看一看 groupby 函数. In [1]: # Import libraries import pandas as pd import sys In [2]: print(' ...

  6. JavaScript获取非行间样式

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  7. jQueryDOM操作模块(二)

    DOM模块 1.优化框架结构 目标:在实现功能基础上优化代码使得框架更简单易用 1.1 简化存储DOM元素的容器 - elements 目标:使用 this 作为容器 1.1.1 使用 element ...

  8. PostgreSQL的HA解决方案-2负载均衡(load balance)

    一.部署说明 1.1 实施环境 本文档实验环境如下: PGSQL主机: 192.168.1.45 PGSQL备机: 192.168.1.50 软件和系统版本 Pgsql 版本: pgsql 9.2.4 ...

  9. 杭电 1013 Digital Roots

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 反思:思路很简单,但是注意各位数加起来等于10的情况以及输入0的时候结束程序该怎么去表达 #in ...

  10. bootstrap与jQuery结合的动态进度条

    此款进度条实现的功能: 1.利用了bootstrap的进度条组件. a.在最外层的<div>中加入class .progress,在里层<div>加入class .progre ...