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. Bone Collector(hdoj--2602--01背包)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. 线性回归模型之LinearRegression和SGDRegressor

    用美国波士顿的房价数据来介绍如何使用LR和SGDR模型进行预测 # 从sklearn.datasets导入波士顿房价数据读取器. from sklearn.datasets import load_b ...

  3. Tomcat 日志切割

    一.installing 日志轮训工具 yum  install cronolog -y 二.安装.修改tomcat文件 wget  http://mirrors.shuosc.org/apache/ ...

  4. week2 notebook2

    Beginning day2: 1.基础数据类型宏观: 1.1.整型:int:1,2,3 1.2.字符串:str:‘anthony’ 1.2.1: 索引:索引即下标,就是字符串组成的元素从第一个开始, ...

  5. deeplearning4j – 分布式DL开源项目

    原文链接:http://www.52ml.net/16157.html Deeplearning4j is the first commercial-grade deep learning libra ...

  6. profibus

    在研究profibus之前先提出问题,带着问题查看 profibus跟硬件无关?只是软件上的协议复杂? profibus和modbus的区别? 解读: profibus跟硬件关系不大,profibus ...

  7. uva 1658 Admiral 【 最小费用最大流 】

    拆点,每个点拆成 i,i' 在i 和i‘之间连一条费用为0,容量为1的边,就可以保证每个点只经过一次 特殊的点,1和n之间,,,n和2*n之间连一条费用为0,容量为2的边,可以求出两条路径 #incl ...

  8. python tips: is同一性运算符

    is用来判断两个对象是不是同一个对象,通过id()函数取对象地址进行判断.python会缓存一些小的整数,以及只包含字母数字以及下划线的字符串.所以在对于这些值的时候,is判断为True. >& ...

  9. 【数据分析】算法+Echarts小练

    ''' 处理逻辑: 按number去处理 先遍历所有的number挨个去找有没有在列表里的,在列表里的拿出另外一个append 把number去除的列表 ''' li = [] with open(r ...

  10. Mysql笔记2-----重要小点

    1.逻辑删除: