| Online Judge | Online Exercise | Online Teaching | Online Contests | Exercise Author | |||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |||||
| F.A.Q Hand In Hand Online Acmers Forum | Discuss Statistical Charts | Problem Archive Realtime Judge Status Authors Ranklist Search | C/C++/Java Exams ACM Steps Go to Job Contest LiveCast ICPC@China | Best Coder beta VIP | STD Contests Virtual Contests DIY | Web-DIY beta Recent Contests | ||||||
| HOT~ 杭电2015级新生如何加入ACM集训队? | |||||||||
| # 小希的迷宫**Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 36454 Accepted Submission(s): 11155 ** Problem Description上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头路)。小希现在把她的设计图给你,让你帮忙判断她的设计图是否符合她的设计思路。比如下面的例子,前两个是符合条件的,但是最后一个却有两种方法从5到达8。 |
6 8 5 3 5 2 6 4 5 6 0 0 8 1 7 3 6 2 8 9 7 5 7 4 7 8 7 6 0 0 3 8 6 8 6 4 5 3 5 6 5 2 0 0 -1 -1
Sample Output
Yes Yes No
| | [Home](http://acm.hdu.edu.cn/) \| [Top](http://acm.hdu.edu.cn/showproblem.php?pid=1272#top) | Hangzhou Dianzi University Online Judge 3.0 Copyright © 2005-2015 [HDU ACM Team](mailto:acm@hdu.edu.cn). All Rights Reserved. [Designer & Developer ](http://acm.hdu.edu.cn/about_us/developer.php): [Wang Rongtao]() [LinLe]() [GaoJie](mailto:gjavac@gmail.com) [GanLu](mailto:gl8997@gmail.com) Total 0.000000(s) query 5, Server time : 2015-09-18 15:12:18, Gzip enabled | [Administration](http://acm.hdu.edu.cn/admin) |
| ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | | | | | |
\
\
思路:图中不能有环即点数-1=边数。然后判断是否全图均为一个联通块。
\
\
```cpp
#include <cstdio>
#include <iostream>
#include <cstring>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int a[1000000],s[1000000];
int cnt;
int fi(int r)
{
return r==a[r]?r:a[r]=fi(a[r]);
}
void sor(int x,int y)
{
int p=fi(x);
int q=fi(y);
a[p]=q;
}
int main()
{
int n,m,i,j,k;
while(~scanf("%d%d",&n,&m))
{
if(m==-1&&n==-1)
{
break;
}
else if(!n&&!m)
{
printf("Yes\n");continue;
}
cnt=0;
memset(a,0,sizeof(a));
memset(s,0,sizeof(s));
if(a[m]==0)
{
a[m]=m;
s[cnt++]=m;
}
if(a[n]==0)
{
a[n]=n;
s[cnt++]=n;
}
sor(n,m);
int x,y,d=1;
while(~scanf("%d%d",&x,&y))
{
if(!x&&!y)
break;
d++;
if(!a[x])
{
a[x]=x;
s[cnt++]=x;
}
if(!a[y])
{
a[y]=y;
s[cnt++]=y;
}
sor(x,y);
}
int c=0;
for(i=0;i<cnt;i++)
{
if(a[s[i] ]==s[i] )
c++;
}
if(c==1&&cnt-1==d)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
\