码迷,mamicode.com
首页 > 其他好文 > 详细

并查集模板

时间:2020-01-23 19:56:58      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:audio   const   spl   one   void   code   else   display   +=   

const int N=120;
int father[N];
int rank1[N];
void init(int Size)
{
    for(int i=1;i<=Size;++i)
        father[i]=i,rank1[i]=0;

}
int Find(int x)
{
    while(x!=father[x])
        x=father[x];
    return x;
}
bool Union(int x,int y)
{
    int fx,fy;
    fx=Find(x),fy=Find(y);
    if(fx==fy)
        return false;
    else if(rank1[fx]>=rank1[fy])
    {
        father[fy]=fx;
        rank1[fx]+=rank1[fy];
    }
    else
    {
        father[fx]=fy;
        rank1[fy]+=rank1[fx];
    }
    return true;
}

 

并查集模板

标签:audio   const   spl   one   void   code   else   display   +=   

原文地址:https://www.cnblogs.com/waryan/p/12231009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!