File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
docs/codingprob/FDS/template Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments