uva 10596 Morning Walk (欧拉回路)
来源:互联网 发布:移动网络办理投诉电话 编辑:程序博客网 时间:2024/05/21 09:14
uva 10596 Morning Walk
Kamal is a Motashota guy. He has got a new job in Chittagong . So, he has moved to Chittagong from Dinajpur. He was getting fatter in Dinajpur as he had no work in his hand there. So, moving to Chittagong 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 Chittagong and 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 number R denotes the number of roads (0 ≤ R ≤ 10000). Then there will beR lines each containing two numbers c1 andc2 indicating 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
题目大意:判断所给出的数据能否形成一个环。
解题思路:普通欧拉回路。
>#include<string.h>int num[250], gra[250];int get(int x) {return num[x] != x ? get(num[x]) : x;}int main() {int n, m;while (scanf("%d %d\n", &n, &m) == 2) {memset(gra, 0, sizeof(gra));for (int i = 0; i < 250; i++) {num[i] = i;}for (int i = 0; i < m; i++) {int a, b;scanf("%d %d", &a, &b);gra[a]++;gra[b]++;num[get(a)] = get(b);}int begin = 0, flag = 0;for (int i = 0; i < 250; i++) {if (gra[i] && get(i) == i) {begin = i;break;}}for (int i = 0; i < n; i++) {flag += gra[i] % 2;if (gra[i] && begin != get(i)) flag++;}if (m == 0) flag = 1; //注意特殊情况,数据会卡这里if (flag) printf("Not Possible\n"); else printf("Possible\n"); }return 0;}
- UVa 10596 - Morning Walk(欧拉回路)
- UVa 10596 Morning Walk ( 欧拉回路 )
- Morning Walk - UVa 10596 欧拉回路
- uva 10596 Morning Walk(欧拉回路)
- uva 10596 Morning Walk(欧拉回路)
- uva 10596 - Morning Walk (欧拉回路~~~)
- UVA - 10596 Morning Walk (欧拉回路+dfs)
- uva 10596 Morning Walk (欧拉回路)
- UVa 10596 - Morning Walk, 赤裸裸的欧拉回路
- UVA 10596 Morning Walk 简单的k欧拉回路
- UVA 10196 Morning Walk(欧拉回路)
- UVA - 10596 - Morning Walk (欧拉回路!并查集判断回路)
- 10596 - Morning Walk//欧拉回路
- 10596 - Morning Walk(欧拉回路 + dfs)
- UVa 10596 - Morning Walk(无向图,欧拉回路)
- Morning Walk-uva 经典的欧拉回路
- UVa 10596 - Morning Walk 有向图的欧拉回路
- UVA 10596 Morning Walk[无向图的欧拉回路]
- 图像处理和计算机视觉中的经典论文
- phoenix upsert date 类型数据
- C++ 线程池的封装实现
- java中this用法
- iOS 8自定义动画转场上手指南
- uva 10596 Morning Walk (欧拉回路)
- Sencha学习笔记2:打包您的第一个Sencha安卓应用apk安装包
- SeekBar如何设置不能拖动,做到和ProgressBar一样
- eclipse android 设置及修改生成apk的签名文件
- Linux守护进程
- 电源选项里也没有“休眠”
- Windows 下搭建LDAP服务器
- android 多线程数据库读写分析与优化
- Eclipse ADT的Custom debug keystore所需证书规格