class UnionFind
{
public:
vector<int> parent,count;
UnionFind(int n){
parent.resize(n, -1);
count.resize(n, 1);
}
int find(int x){
return (this->parent[x] == -1)? x : find(this->parent[x]);
}
void Union(int a, int b){
int pA = find(a) , pB = find(b);
if(pA != pB){
this->parent[pB] = pA;
this->count[pA] += this->count[pB];
}
}
};