set<int>se; set<int>::iterator it; inttofind(int x){ if (f[x] != x){ f[x] = tofind(f[x]); } return f[x]; } voidtojoin(int a, int b){ a = tofind(a); b = tofind(b); if (a != b){ f[a] = b; } } voidinit(){ for (int i = 0; i <= N; i++){ f[i] = i; } se.clear(); } intmain(){ int a, b; int f = 0; init(); while(cin >> a >> b){ if (!a && !b){ if (f) puts("No"); else{ int sum = 0; for (it = se.begin(); it != se.end(); it ++){ if (tofind(*it) == *it) sum++; if (sum >= 2) break; } if (sum >= 2) puts("No"); else{ puts("Yes"); } } f = 0; init(); } elseif (a == -1 && b == -1) break; else{ se.insert(a); se.insert(b); if (tofind(a) != tofind(b)) tojoin(a, b); else f = 1; } } return0; }
queue<int>q; inttofind(int x){ if (f[x] != x){ f[x] = tofind(f[x]); } return f[x]; } voidtojoin(int a, int b){ a = tofind(a); b = tofind(b); if (a != b){ f[a] = b; } } voidinit(){ for (int i = 0; i <= N; i++){ f[i] = i; } while(!q.empty()) q.pop(); } intmain(){ int a, b; int f = 0; init(); while(cin >> a >> b){ if (!a && !b){ if (f) puts("No"); else{ int sum = 0; while(!q.empty()){ int k = q.front(); q.pop(); if (tofind(k) == k) sum++; if (sum >= 2) break; } if (sum >= 2) puts("No"); else{ puts("Yes"); } } f = 0; init(); } elseif (a == -1 && b == -1) break; else{ q.push(a); q.push(b); if (tofind(a) != tofind(b)) tojoin(a, b); else f = 1; } } return0; }