并查集

int Find (int t)//找
{
    if(vest[t]==0)return t;//找到其祖先vest[]d的数组初始化为零
    return Find(vest[t]);//继续查找
}
void HeBing(int a,int b)
{
    int x=Find(a);
    int y=Find(b);
    if(x!=y)vest[x]=y;//如果两个数的祖先不一样就将两个赋予相同的祖先
}
 
 
梦里不知身是客,一晌贪欢。
原文地址:https://www.cnblogs.com/dccmmtop/p/5041334.html