uva 10596 - Morning Walk

Problem H

Morning Walk

Time Limit

3 Seconds

 

Kamal is aMotashota guy. He has got a new job in Chittagong. So, he has moved to Chittagong fromDinajpur. 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 helpKamal 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 number R denotes the number of roads (0 ≤ R ≤ 10000). Then there will beR lines each containing two numbers c1 andc2 indicating the intersections connecting a road.

 

Output

Print a single line containing the text “Possible” without quotes if it is possible forKamal 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

 

Problemsetter: Muhammad Abul Hasan

International Islamic UniversityChittagong

灰常蛋疼的一个题目,看他的样例像是有向图,看别人的解题报告都说是无向图......

无向图的欧拉回路问题,条件为连通图且所有节点度数为偶数

#include <stdio.h>
#define size 210
int num,f,n,visit[size],map[size][size],degree[size];
int dfs(int x)
{int  i;
 for (i=0;i<n;i++)
 if ((visit[i]==1)&&(map[x][i]==1))
 {visit[i]=0; ++num;
  dfs(i);
 }
};
int main()
{int i,j,r,x,y;
 while (scanf("%d%d",&n,&r)!=EOF)
 {
  for (i=0;i<n;i++)
  for (j=0;j<n;j++)
  map[i][j]=0;
  for (i=0;i<n;i++)
  {visit[i]=1; degree[i]=0;}
  for (i=1;i<=r;i++)
  {scanf("%d%d",&x,&y);
   map[x][y]=1;
   ++degree[x];
   ++degree[y];
  }
  if (r>0) f=1; else f=0;
  for (i=0;i<n;i++)
  if (degree[i]%2==1) {f=0;break;}
  if (f) {num=1; visit[0]=0; dfs(0); //开始写的visit[n-1];dfs(n-1);死活过不了,改成0就过了,题目也没说0是起点,判断连通性而已。真奇怪.....
          if (num!=n) f=0;
         }
  if (f) printf("Possible\n");
    else printf("Not Possible\n");
 }
 return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值