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\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(欧拉回路)的更多相关文章
- Uva 10596 - Morning Walk 欧拉回路基础水题 并查集实现
题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起 ...
- UVa 10596 Moring Walk【欧拉回路】
题意:给出n个点,m条路,问能否走完m条路. 自己做的时候= =三下两下用并查集做了交,WA了一发-后来又WA了好几发--(而且也是判断了连通性的啊) 搜了题解= = 发现是这样的: 因为只要求走完所 ...
- 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 ...
- UVA 10054 the necklace 欧拉回路
有n个珠子,每颗珠子有左右两边两种颜色,颜色有1~50种,问你能不能把这些珠子按照相接的地方颜色相同串成一个环. 可以认为有50个点,用n条边它们相连,问你能不能找出包含所有边的欧拉回路 首先判断是否 ...
- UVa 10129单词(欧拉回路)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 10917 A Walk Through the Forest
A Walk Through the Forest Time Limit:1000MS Memory Limit:65536K Total Submit:48 Accepted:15 Descrip ...
- uva 10196 Check The Check
题目:10196 - Check The Check 思路:水题..模拟 这个代码,前半部分是在数统机房上课的时候写的,挫了点,懒得改了. #include <cstdio> #inclu ...
- UVa 10054 项链(欧拉回路)
https://vjudge.net/problem/UVA-10054 题意:有一种由彩色珠子连接成的项链.每个珠子的两半由不同颜色组成.相邻两个珠子在接触的地方颜色相同.现在有一些零碎的珠子,需要 ...
- UVA - 10196:Check The Check
类型:简单模拟 大致题意:已知国际象棋行棋规则,给你一个局面,问是否将军?谁将谁的军?(保证不会同时将军) 思路:都以小写字母 测试 是否将 大写字母. 然后一个局面测两次(一次直接测,一次反转棋盘, ...
随机推荐
- linux中字符串转换函数 simple_strtoul
Linux内核中提供的一些字符串转换函数: lib/vsprintf.c 1. unsigned long long simple_strtoull(const char *cp, char **en ...
- angular里使用vue/vue组件怎么在angular里用
欢迎加入前端交流群交流知识&&获取视频资料:749539640 如何在angularjs(1)中使用vue参考: https://medium.com/@graphicbeacon/h ...
- AIX 常用命令汇总(一)
命令 内核 如何知道自己在运行 32 位内核还是 64 位内核? 要显示内核启用的是 32 位还是 64 位,可输入以下命令: bootinfo -K 如何知道自己在运行单处理器还是多处理器内核? / ...
- 虚拟机CentOS设置IP
虚拟机里Centos7的IP地址查看方法 本地虚拟机安装了CentOS 7,想通过ftp上传文件,发现通过ifconfig,没有inet这个属性 查看ens33网卡的配置:vi /etc/syscon ...
- 如何提升SQL语句的查询性能
在对数据库进行操作时,如果SQL语句书写不当,对程序的效率会造成很大影响. 提高SQL效率可以从一下几个方面入手: 1,数据库设计与规划 Primary Key字段的长度尽量小,能用small int ...
- 给统计人讲Python(1)_科学计算库-Numpy
本地代码是.ipynb格式的转换到博客上很麻烦,这里展示部分代码,了解更多可以查看我的git-hub:https://github.com/Yangami/Python-for-Statisticia ...
- BZOJ 4742 DP
思路: Claris大大说了 排序以后 这个可以看成是括号序列 f[i][j][k]表示到了i j个左括号 k个右括号 (f[i][j][k]+=f[i-1][j][k])%=p; if(node[i ...
- unity3d 让物体移动到点击位置
using UnityEngine; using System.Collections; public class test : MonoBehaviour { //在场景中鼠标点击地面后,角色可以移 ...
- Linux目录结构(二)
Linux文件系统结的结构是树形结构,其入口从/开始,了解Linux文件系统的结构,对于我们需要掌握的基础知识点之一. 2.文件系统的组织结构简说: 当您使用Linux的时候,如果您通过ls -la ...
- 函数的arguments
1.arguments a.只能在函数内部被访问. b.arguments是一个伪数组(有下标索引,可以存放多个值,但是他里面没有数组的方法.) c.arguments里面存的是什么?函数的实际参数传 ...