Problem H

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 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的更多相关文章

  1. Uva 10596 - Morning Walk 欧拉回路基础水题 并查集实现

    题目给出图,要求判断不能一遍走完所有边,也就是无向图,题目分类是分欧拉回路,但其实只要判断度数就行了. 一开始以为只要判断度数就可以了,交了一发WA了.听别人说要先判断是否是联通图,于是用并查集并一起 ...

  2. UVa 10596 Moring Walk【欧拉回路】

    题意:给出n个点,m条路,问能否走完m条路. 自己做的时候= =三下两下用并查集做了交,WA了一发-后来又WA了好几发--(而且也是判断了连通性的啊) 搜了题解= = 发现是这样的: 因为只要求走完所 ...

  3. UVa 10917 A Walk Through the Forest

    A Walk Through the Forest Time Limit:1000MS  Memory Limit:65536K Total Submit:48 Accepted:15 Descrip ...

  4. UVA 10196 Morning Walk(欧拉回路)

    Problem H Morning Walk Time Limit 3 Seconds Kamalis a Motashotaguy. He has got a new job in Chittago ...

  5. UVA 503 Parallelepiped walk

    https://vjudge.net/problem/UVA-503 题目 给出一个长方体和长方体上两点的坐标,求两点的沿着长方体表面走的最小距离 题解 沿着表面走就是在展开图上面走,如果分类讨论就需 ...

  6. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  7. UVA - 10917 - Walk Through the Forest(最短路+记忆化搜索)

    Problem    UVA - 10917 - Walk Through the Forest Time Limit: 3000 mSec Problem Description Jimmy exp ...

  8. UVA 10917 Walk Through the Forest SPFA

    uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...

  9. UVA 10917 Walk Through the Forest(dijkstra+DAG上的dp)

    用新模板阿姨了一天,换成原来的一遍就ac了= = 题意很重要..最关键的一句话是说:若走A->B这条边,必然是d[B]<d[A],d[]数组保存的是各点到终点的最短路. 所以先做dij,由 ...

随机推荐

  1. python 面向对象九 定制类

    一.定制类,实质就是我们自己重写特殊函数 看到类似__slots__这种形如__xxx__的变量或者函数名就要注意,这些在Python中是有特殊用途的. __slots__我们已经知道怎么用了,__l ...

  2. bzoj 1511: [POI2006]OKR-Periods of Words【kmp】

    n-ne[n]是n的最长循环节长度,其实就是n-最短前缀=后缀长度 然后我们要求最短循环节,其实就是ne一直往前跳,跳到不能跳为止,这时的n-ne[n]就是n的最短循环节长度 #include< ...

  3. P4475 巧克力王国(KDTree)

    传送门 首先可以把约束条件看成一条直线,然后每个巧克力看成一个点,求给定区域内的点权和 用KDTree,每次判断一下当前矩形是否整个都在里面或都在外面,是的话直接返回,否则的话递归 注意,必须该矩形四 ...

  4. 1.1.1最短路(Floyd、Dijstra、BellmanFord)

    转载自hr_whisper大佬的博客 [ 一.Dijkstra 比较详细的迪杰斯特拉算法讲解传送门 Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算 ...

  5. 题解报告:hdu 1257 最少拦截系统(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是 ...

  6. Android内存堆上限Android的缺省值是16M(某些机型是24M)

    转自: http://www.cnblogs.com/jacktu/archive/2010/12/30/1921475.html 大家都知道Android的上层应用是基于 Dalvik Virtua ...

  7. ORA-28002错误原因及解决办法

    在oracle database 11g中,默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”所导致.密码过期后,业务进程连接数据库异常,影响业务使用.数据库密码过 ...

  8. Java操作pdf: JarsperReport的简单使用

    在企业级应用开发中,报表生成.报表打印下载是其重要的一个环节.除了 Excel 报表之外,PDF 报表也有广泛的应用场景. 目前世面上比较流行的制作 PDF 报表的工具如下: iText PDF :i ...

  9. hihocoder1710 等差子数列

    思路: 将数列合并之后使用线段树.边界条件容易写错. 实现: #include <bits/stdc++.h> using namespace std; ; const int INF = ...

  10. [Luogu2901][USACO08MAR]牛慢跑Cow Jogging Astar K短路

    题目链接:https://daniu.luogu.org/problem/show?pid=2901 Astar的方程$f(n)=g(n)+h(n)$,在这道题中我们可以反向最短路处理出$h(n)$的 ...