您的位置:首页
UVA 10196 Morning Walk(欧拉回路)
2017-05-31 16:51
411 查看
Problem H | Morning Walk |
Time Limit | 3 Seconds |
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 |
题意:给出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 Morning Walk(判欧拉回路)
- UVa 10596 - Morning Walk 有向图的欧拉回路
- uva 10596 Morning Walk(欧拉回路)
- UVa 10596 - Morning Walk(欧拉回路)
- uva10596 Morning Walk (无向图,欧拉回路,存在性判断)
- uva 10596 - Morning Walk (欧拉回路~~~)
- UVA 10596 Morning Walk 简单的k欧拉回路
- UVa 10596 - Morning Walk(无向图,欧拉回路)
- Morning Walk - UVa 10596 欧拉回路
- UVa 10596 - Morning Walk, 赤裸裸的欧拉回路
- UVA - 10596 - Morning Walk (欧拉回路!并查集判断回路)
- uva 10596 Morning Walk(欧拉回路)
- uva 10596 Morning Walk (欧拉回路)
- UVa 10596 Morning Walk ( 欧拉回路 )
- uva 10596 Morning Walk
- UVA 10054 无向图的欧拉回路输出路径
- uva 10596 Morning Walk
- UVA10596- Morning Walk
- The Necklace ——UVA - 10054(欧拉回路)