题目:
https://pintia.cn/problem-sets/994805046380707840/problems/994805068539215872
并查集的复习:
int father[10000];//一个大的集合
//开始前初始化
//设1每个节点的父节点都是自己
//2或者都设为-1
//查找,返回节点的祖宗
int find(int x){
whlie(x != father[x]){
x = fatehr[x];
}
return x;
}
//把a,b的祖宗进行合并
//如果为同一族谱则不管
void Union(int a,int b){
int faA = find(a);
int faB = find(b);
if(faA > faB)
father[faA] = faB;
else if(faA < faB)
father[faB] = faA;
}