1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn=1e5+5; 7 8 int x; 9 int f[maxn];10 int find(int x){11 if(x!=f[x]){12 f[x]=find(f[x]);13 }14 return f[x];15 }16 void init(){17 for(int i=0;i<=100000;i++) 18 f[i]=i;19 }20 set S;21 int main(){22 int a,b;int flag=1;23 std::ios::sync_with_stdio(false);24 init();25 while(cin>>a>>b){26 if(a==-1&&b==-1) break;27 if(a==0&&b==0)28 {29 //cout <<"flag="< <
::iterator it=S.begin();41 if(!S.empty()) sign=find(*it),it++;42 for(;it!=S.end();it++){43 if(find(*it)!=sign) flag=0;44 //cout <<"in";45 }46 if(flag) cout <<"Yes\n";47 else cout <<"No\n";48 }49 //cout <<"in";50 flag=1;51 S.clear();52 init();53 }54 else55 {56 S.insert(a);S.insert(b); 57 int fa=find(a);58 int fb=find(b);59 //cout <<"root"<
<<" "< <