Description
The last time 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
Input contains multiple sets of data, each set of data is a list of integers ending in 0 0, representing the number of two rooms connected by a channel. 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
For each set of data entered, the output includes only one row. If the maze conforms to Xiaoxi's idea, then output "Yes", otherwise output "No".
Sample Input
6 8 5 3 5 2 6 45 6 0 08 1 7 3 6 2 8 9 7 57 4 7 8 7 6 0 03 8 6 8 6 45 3 5 6 5 2 0 0-1-1
Sample Output
Yesyesno: Let you judge whether there is a ring. Using if there is a ring there is so the number of sides +1 = vertex number, personally think that do not need kruscal bar ... Because even if there is more than one tree, and no constituent ring still satisfies this condition, the kruscal judgment is based on the same parent section of the two points. So it's easy to get to the edge, and the number of points ... Because the sequence number of points is not fixed, the net incredibly use a function to get out--| | Orzset<int> S, S.insect (), s.size ();
#include <stdio.h>#include<Set>using namespacestd;Set<int>S;intMain () {Freopen ("a.txt","R", stdin); intb; while(SCANF ("%d%d", &a,&b) && (a!=-1|| b!=-1)) { if(a==0&&b==0) printf ("yes\n"); intnum=1; S.insert (a); S.insert (b); while(SCANF ("%d%d", &a,&b) && (a| |b) {S.insert (a); S.insert (b); Num++; } printf ("\ n") ; if(S.size ()-1==num) printf ("yes\n");//a rule that satisfies the number of edges plus a vertex (regardless of the heavy edges and the edges pointing to itself) Elseprintf"no\n"); S.clear (); } return 0;}
View Code
Please poke it in the original.
The maze of Xiaoxi