目录
0.知识背景
博文->【数据结构之并查集】并查集详解(零基础入门,超级有趣的!!!)
1.模板
int pre[maxn];
int find(int root)//找他在的门派的掌门人
{
int son,tmp;
son = root;
while(root != pre[root])
{
root = pre[root];
}
while(son != root)//压缩路径
{
tmp = pre[son];
pre[son] = root;
son = tmp;
}
return root;
}
void join(int a,int b)//a,b结拜
{
int x = find(a);
int y = find(b);
if(x != y)
pre[x] = y;
}