Morning Walk - UVa 10596 欧拉回路
来源:互联网 发布:花千骨网络流行语 编辑:程序博客网 时间:2024/05/17 08:18
Morning Walk
Time Limit
3 Seconds
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 inDinajpur 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 by N (2 ≤ N ≤ 200). The road intersections are assumed to be numbered from 0 to N-1. The second number R denotes the number of roads (0 ≤ R ≤ 10000). Then there will be R lines each containing two numbers c1 and c2indicating 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
题意:是否存在欧拉回路。
思路:先判断连通性,然后判断是否每个点的度都为偶数。
AC代码如下:
#include<cstdio>#include<cstring>using namespace std;int n,m,d[210],p[210],vis[210];int find(int x){ return p[x]==x ? x : p[x]=find(p[x]);}void Union(int x,int y){ x=find(x); y=find(y); p[x]=y;}bool check(){ int i,ret=0; for(i=0;i<n;i++) if(vis[i] && p[i]==i) ret++; return ret==1;}int main(){ int i,j,k,u,v; bool flag; while(~scanf("%d%d",&n,&m)) { memset(d,0,sizeof(d)); memset(vis,0,sizeof(vis)); for(i=0;i<=n;i++) p[i]=i; for(i=1;i<=m;i++) { scanf("%d%d",&u,&v); d[u]++; d[v]++; vis[u]=vis[v]=1; Union(u,v); } flag=1; if(!check()) flag=0; for(i=0;i<n;i++) if(vis[i] && (d[i]&1)) flag=0; if(flag) printf("Possible\n"); else printf("Not Possible\n"); }}
- UVa 10596 - Morning Walk(欧拉回路)
- UVa 10596 Morning Walk ( 欧拉回路 )
- Morning Walk - UVa 10596 欧拉回路
- uva 10596 Morning Walk(欧拉回路)
- UVa 10596 - Morning Walk, 赤裸裸的欧拉回路
- UVA 10596 Morning Walk 简单的k欧拉回路
- uva 10596 Morning Walk(欧拉回路)
- uva 10596 - Morning Walk (欧拉回路~~~)
- UVA - 10596 Morning Walk (欧拉回路+dfs)
- uva 10596 Morning Walk (欧拉回路)
- 10596 - Morning Walk//欧拉回路
- 10596 - Morning Walk(欧拉回路 + dfs)
- UVA - 10596 - Morning Walk (欧拉回路!并查集判断回路)
- Morning Walk-uva 经典的欧拉回路
- UVA 10196 Morning Walk(欧拉回路)
- UVa 10596 - Morning Walk 有向图的欧拉回路
- UVa 10596 - Morning Walk(无向图,欧拉回路)
- UVA 10596 Morning Walk[无向图的欧拉回路]
- SHA1算法详解
- 11招教你如何玩转数据库设计(转)
- oracle的导入导出表
- java(29) - 线程详解
- HDU 1022 栈的问题
- Morning Walk - UVa 10596 欧拉回路
- jeecms框架单点登录功能的实现
- UVA201 Squares
- 1008. Elevator (20)
- 输出完数
- 批量插入SQL
- 算法生成太极八卦图
- 限制avd网速
- cocos2d-x 3.0 + lua 开发问题与解决吐槽 - PART 1