1 const int maxn = 100010; 2 int fa[maxn]; 3 4 int find(int x) 5 { 6 if (fa[x] == x) return x; 7 fa[x] = find(fa[x]); 8 return fa[x]; 9 } 10 11 void merge(int a, int b) 12 { 13 fa[find(a)] = find(b); 14 } 15 16 bool check(int a, int b) 17 { 18 return find(a) == find(b); 19 }