Skip to content

Commit 8c17cdb

Browse files
committed
add disjoint0
1 parent 34e1229 commit 8c17cdb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// https://vjudge.net/contest/352513#problem/C
2+
// HDU- 1272
3+
#include <cstdio>
4+
#include <algorithm>
5+
const int N=1e5+10;
6+
using namespace std;
7+
int n,f[N],vis[N],flag;
8+
inline int sf(int x){return x==f[x]?x:f[x]=sf(f[x]);}
9+
inline void merge(int x,int y)
10+
{
11+
int xx=sf(x),yy=sf(y);
12+
if(xx==yy){flag=1;return ;}
13+
f[xx]=yy;
14+
}
15+
int main()
16+
{
17+
int x,y;
18+
while(scanf("%d%d",&x,&y)==2,(~x||~y))
19+
{
20+
if(!x&&!y){puts("Yes");continue;}
21+
for(int i=1;i<N;i++)
22+
f[i]=i,vis[i]=0;
23+
flag=0,merge(x,y),vis[x]=vis[y]=1;
24+
while(scanf("%d%d",&x,&y)==2,(x||y))
25+
merge(x,y),vis[x]=vis[y]=1;
26+
if(flag) puts("No");
27+
else
28+
{
29+
int cnt=0;
30+
for(int i=1;i<N;i++)
31+
if(f[i]==i&&vis[i]) cnt++;
32+
if(cnt==1) puts("Yes");
33+
else puts("No");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)