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,由 ...
随机推荐
- VS2013程序打包报 ISEXP : error -****: An error occurred streaming
原因缺少打包文件 解决方案: 找到打包文件 右击选择 downLoad selected item
- _bzoj2005 [Noi2010]能量采集
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2005 令F(i)表示i | gcd(x, y)的对数,f(i)表示gcd(x, y) = i ...
- 题解报告:hdu 1124 Factorial(求N!尾数有多少个0。)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1124 Problem Description The most important part of a ...
- 移动端如何定义字体font-family
移动端如何定义字体font-family 中文字体使用系统默认即可,英文用Helvetica /* 移动端定义字体的代码 */ body{font-family:Helvetica;} 参考<移 ...
- ASP.NET MVC+Bootstrap个人博客之praise.js点赞特效插件(二)
1. 为啥要做这个点赞插件? praise.js是一款小巧的jQuery点赞插件,使用简便,效果美观. 在做个人博客时遇到了文章点赞问题.联想到各大社交网络中的点赞特效:手势放大.红心放大等等, ...
- [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)
本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/sorting-fi ...
- Java_JDBC连接数据库_使用读取配置文件的方式
package com.homewoek3_4.dao; import java.io.IOException; import java.io.InputStream; import java.sql ...
- js点击修改按钮后修改
<button id="click">改变内容</button> <div id="t">要改变的内容</div> ...
- JS格式化工具(转)
<html> <head> <title>JS格式化工具 </title> <meta http-equiv="content-type ...
- 外文翻译 《How we decide》赛场上的四分卫
本书导言翻译 为了能看懂这一章,先做了如下的功课: 百度百科 四分卫 国家橄榄球联盟中文站 在2002年超级碗赛场上,比赛的时间仅剩80秒,两队比分持平.新英格兰爱国者队于17码的位置执球,他们的对手 ...