Question Analysis
Query set Problems
Notes
1. the requirements in the questions are relatively broad, which leads to the conclusion that there is only a loop as an error. However, there are more than one error, it is also wrong if there are two trees or multiple trees (from A to B );
2. The connection between itself and itself is also incorrect.
Possible test data
1 1 0 00 01 2 3 4 0 01 2 2 3 3 4 0 01 3 5 3 0 0-1 -1
Answer:
NoYesNoYesYes
Reference Code
# Include
Int fa [100005]; // parent array int visit [100005]; // indicates whether int load () {int I; for (I = 0; I <100005; I ++) fa [I] = I;} int find (int x) {if (x! = Fa [x]) fa [x] = find (fa [x]); return fa [x];} int main () {int m, n; int x, y, fx, fy; int I, flag, flag1, count; while (scanf (% d, & m, & n) {flag = 0; count = 0; flag1 = 0; if (m =-1 & n =-1) break; else if (m = 0 & n = 0 ); else {load (); memset (visit, 0, sizeof (visit); fa [m] = n; visit [m] = 1; visit [n] = 1; if (m = n) flag = 1; while (scanf (% d, & x, & y), x & y) {fx = find (x ); fy = find (y); visit [x] = 1; visit [Y] = 1; if (fx = fy) flag = 1; else fa [fx] = fy ;}} for (I = 0; I <100005; I ++) {if (visit [I] & fa [I] = I) flag1 ++; if (visit [I]) count ++ ;}if (count = 0) printf (Yes); // test data else if (! Flag & flag1 = 1) printf (Yes); // No loop and only one else printf (No);} return 0 ;}