uva 10596 - Morning Walk
Problem H |
|
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 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 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 c2 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 <iostream>
#include <stack>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <stack>
#include <list>
#include <sstream>
#include <cmath> using namespace std; #define ms(arr, val) memset(arr, val, sizeof(arr))
#define mc(dest, src) memcpy(dest, src, sizeof(src))
#define N 205
#define INF 0x3fffffff
#define vint vector<int>
#define setint set<int>
#define mint map<int, int>
#define lint list<int>
#define sch stack<char>
#define qch queue<char>
#define sint stack<int>
#define qint queue<int>
int degree[N], fa[N], visit[N];
int n, r; int find(int x)
{
return fa[x] == - ? x : fa[x] = find(fa[x]);
} void _union(int x, int y)
{
int fx = find(x), fy = find(y);
if (fx != fy)
{
fa[fx] = fy;
}
} bool check()
{
int res = ;
for (int i = ; i < n; i++)
{
if (visit[i] && fa[i] == -)
{
res++;
}
}
if (res != )
{
return false;
} for (int i = ; i < n; i++)
{
if (visit[i] && (degree[i] & ))
{
return false;
}
}
return true;
} void init()
{
ms(degree, );
ms(fa, -);
ms(visit, );
} int main()
{
int s, e;
while (~scanf("%d", &n))//其实的无向图的欧拉回路,看网上说想了好久才想明白
{
init();
scanf("%d", &r);
while (r--)
{
scanf("%d%d", &s, &e);
_union(s, e);
degree[s]++;
degree[e]++;
visit[e] = visit[s] = ;//可能存在孤立的点,所以需要标记
}
if (check())
puts("Possible");
else
puts("Not Possible");
}
return ;
}
uva 10596 - Morning Walk的更多相关文章
- Uva 10596 - Morning Walk 欧拉回路基础水题 并查集实现
题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起 ...
- UVa 10596 Moring Walk【欧拉回路】
题意:给出n个点,m条路,问能否走完m条路. 自己做的时候= =三下两下用并查集做了交,WA了一发-后来又WA了好几发--(而且也是判断了连通性的啊) 搜了题解= = 发现是这样的: 因为只要求走完所 ...
- 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 Morning Walk(欧拉回路)
Problem H Morning Walk Time Limit 3 Seconds Kamalis a Motashotaguy. He has got a new job in Chittago ...
- UVA 503 Parallelepiped walk
https://vjudge.net/problem/UVA-503 题目 给出一个长方体和长方体上两点的坐标,求两点的沿着长方体表面走的最小距离 题解 沿着表面走就是在展开图上面走,如果分类讨论就需 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- UVA - 10917 - Walk Through the Forest(最短路+记忆化搜索)
Problem UVA - 10917 - Walk Through the Forest Time Limit: 3000 mSec Problem Description Jimmy exp ...
- UVA 10917 Walk Through the Forest SPFA
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...
- UVA 10917 Walk Through the Forest(dijkstra+DAG上的dp)
用新模板阿姨了一天,换成原来的一遍就ac了= = 题意很重要..最关键的一句话是说:若走A->B这条边,必然是d[B]<d[A],d[]数组保存的是各点到终点的最短路. 所以先做dij,由 ...
随机推荐
- BZOJ 1001 [BeiJing2006]狼抓兔子 (UVA 1376 Animal Run)
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 24727 Solved: 6276[Submit][ ...
- centos 7添加快捷键
转自:http://www.cnblogs.com/flying607/p/5730867.html centos7中不自带启动终端的快捷键,可以自定义添加. 点击右上角的用户名,点击设置,在设置面板 ...
- 超级实用的VSCode插件,帮你大幅提高工作效率
Visual Studio Code是一个轻量级但功能强大的源代码编辑器,可在桌面上运行,适用于Windows,macOS和Linux. 它内置了对JavaScript,TypeScript和Node ...
- centos mysql数据库忘记密码修改
1.vim /etc/my.cnf 2.在[mysqld]中添加 skip-grant-tables 例如: [mysqld]skip-grant-tablesdatadir=/var/lib/mys ...
- 数据结构 - 链栈的实行(C语言)
数据结构-链栈的实现 1 链栈的定义 现在来看看栈的链式存储结构,简称为链栈. 想想看栈只是栈顶来做插入和删除操作,栈顶放在链表的头部还是尾部呢?由于单链表有头指针,而栈顶指针也是必须的,那干吗不让它 ...
- _bzoj1015 [JSOI2008]星球大战starwar【并查集】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1015 倒过来做就ok了. #include <cstdio> #include ...
- jQuery 常见面试题
一 :Q: What is the difference between .get(), [], and .eq()? A: eq返回原生jQuery对象,截取某些el元素生成Jquery新对象 ge ...
- GUI初步和frame&panel
java的话这个GUI其实不是什么重点,但我们也要学习,重点是学习这种图形编程的思路. java里面对于图形的一些类都封装在了AWT和它的一些子包里.AWT(抽象窗口开发包) 当 ...
- 转】RMySQL数据库编程指南
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/2/ 感谢! Posted: Sep 24, 2013 Ta ...
- wordpress在撰写新文章界面的显示选项按钮点击无反应的解决办法
原文链接:wordpress在撰写新文章界面的显示选项按钮点击无反应的解决办法 最近升级wordpress之后,发现在文章编辑界面的添加新媒体和可视化按钮点击无反应,如下: 然后就在网上找解决办法, ...