const int MAXN=1005;
int father[MAXN];
int find(int x)//寻找根结点
{
if(x==father[x])return x;
return father[x]=find(father[x]); //压缩路径
}
void merge(int a,int b)//合并集合
{
int x=find(a);
int y=find(b);
if(x!=y)father[x]=y;
}
const int MAXN=1005;
int father[MAXN];
int find(int x)//寻找根节点
{
if(x==father[x])return x;
return father[x]=find(father[x]); //压缩路径
}
void merge(int a,int b)//合并两个根节点
{
father[find(a)]=find(b);
}