1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cstdlib> 5 using namespace std; 6 7 #define MAXN 100005 8 int fa[MAXN]; //父节点 9 int vis[MAXN]; 10 int Min = 0xffffff; 11 int Max = 0; 12 13 void init() 14 { 15 for (int i = 0; i < MAXN; i++) 16 { 17 fa[i] = i; 18 } 19 } 20 21 int find(int x) 22 { 23 if (x == fa[x]) 24 return x; 25 else 26 return fa[x] = find(fa[x]); 27 } 28 29 void set_union(int a, int b) 30 { 31 int a1 = find(a); 32 int b1 = find(b); 33 34 if (a1 == b1) 35 return; 36 else 37 { 38 if (a1 < b1) 39 fa[b1] = a1; 40 else 41 fa[a1] = b1; 42 } 43 } 44 45 int main() 46 { 47 int n; 48 while (~scanf("%d",&n)) 49 { 50 init(); 51 for (int i = 0; i < n; i++) 52 { 53 int a, b; 54 scanf("%d %d", &a, &b); 55 56 Min = min(Min, min(a, b)); 57 Max = max(Max, max(a, b)); 58 59 set_union(a, b); 60 } 61 62 int ans = 0; 63 memset(vis, 0, sizeof(vis)); 64 for (int i = Min; i <= Max; i++) 65 { 66 vis[find(i)]++; 67 if (ans < vis[find(i)]) 68 ans = vis[find(i)]; 69 } 70 printf("%d ", ans); 71 } 72 //system("pause"); 73 return 0; 74 }