The maze of XiaoxiTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 30146 Accepted Submission (s): 9354
Problem description Last Gardon Maze Castle Little Nozomi played for a long time (see Problem B), now she also want to design a maze let Gardon to go. But she designed the maze of different ideas, first she thought all the channels should be two-way connectivity, that is, if there is a channel connected to room A and B, then can go through it from room A to room B, but also through it from Room B to room A, in order to improve the difficulty, Xiaoxi hope that any two rooms have and only one path can be connected (unless you go back). Xiao-Nozomi now gives you her design to help you determine whether her design is in line with her design ideas. For example, the first two are eligible, but the last one has two methods of reaching 8 from 5.
Input inputs contain multiple sets of data, each of which is a list of integer pairs ending in 0 0, representing the number of two rooms to which a channel is connected. The number of the room is at least 1 and no more than 100000. There is a blank line between each of the two sets of data.
The entire file ends with two-1.
Output contains only one row for each set of data that is entered. If the maze conforms to Xiaoxi's idea, then output "Yes", otherwise output "No".
Sample Input
6 8 5 3 5 2 6 6 0 1 7 3 6 2 8 9 7 4 7 8 7 6 0 8 6 8 6 4 5 3 5 6 5 2 0 0-1-1
Sample Output
Yesyesno
Authorgardon
Sourcehdu 2006-4 Programming Contest
and check the set of problems, you need to note that the tree can not have a ring, to determine whether it is a tree, and 0 0 under the output situation
from Cao Xuaba There's a new get on set skills, grey often thanks ~ ~
#include <cstdio> #include <iostream> #include <cstring> #include <set>using namespace std;# Define MAXN 1000001int father[maxn];void init () {for (int i=0;i<maxn;i++) father[i]=i;} int Find (int x) {return x==father[x]?x:father[x]=find (father[x]);} void Union (int x,int y) {int fx=find (x); int Fy=find (y); if (fx!=fy) father[fy]=fx;} int main () {//freopen ("In.txt", "R", stdin); int A, B; Set<int> s; Set<int>::iterator ite;; while (scanf ("%d%d", &a,&b)!=eof&& (a!=-1&&b!=-1)) {int c=1; Init (); S.clear (); int flag=1; if (a==0&&b==0) {cout<< "Yes" <<endl; Continue } S.insert (a); S.insert (b); Union (A, b); while (scanf ("%d%d", &a,&b)!=eof) {if (a==0&&b==0) {for (ite=s.b Egin (); Ite!=s.end (); ite++) if (*ite==father[*ite]) C + +; Break } else{if (Find (a) ==find (b)) flag=0; Else Union (A, b); }} if (!flag| | c!=1) cout<< "No" <<endl; else cout<< "Yes" <<endl; } return 0;}
Hdoj 1272. Little Nozomi's Maze