Check simple questions
1 # include <iostream> 2 # include <stdio. h> 3 # include <stdlib. h> 4 # define n 10000005 5 using namespace STD; 6 int par [N]; 7 int M [N]; 8 int find (int x) 9 {10 if (par [x] = x) 11 return X; 12 else13 par [x] = find (par [x]); 14 return par [x]; 15} 16 void Union (int x, int y) 17 {18 int A = find (x); 19 int B = find (y); 20 if (! = B) 21 {22 if (M [a]> = m [B]) // This is to compare 23 {24 par [B] =; 25 m [a] + = m [B]; 26} 27 else28 {29 par [a] = B; 30 m [B] + = m [a]; 31} 32} 33 else34 return; 35} 36 int main () 37 {38 freopen ("input.txt", "r", stdin); 39 int I, x, y, n; 40 while (scanf ("% d", & N )! = EOF) 41 {42 for (I = 0; I <= N; I ++) // The earliest initialization 43 {44 par [I] = I; 45 m [I] = 1; 46} 47 for (I = 1; I <= N; I ++) 48 {49 scanf ("% d ", & X, & Y); 50 Union (x, y); 51} 52 int max =-1; 53 for (I = 0; I <= N; I ++) 54 if (M [I]> MAX) 55 max = m [I]; // find the Max number with the highest number of relatives and output 56 printf ("% d \ n ", max); 57 58} 59 return 0; 60}