#include <iostream>
using namespace std;
int father[100];
//初始化
void init()
{
for(int i = 0; i < 100; ++ i)
{
father[i] = i;
}
}
//查找根节点,按路径优化
int find(int node)
{
if(father[node] != node)
{
father[node] = find(father[node]);
}
return father[node];
}
//合并
void unit(int x, int y)
{
int x0 = find(x);
int y0 = find(y);
father[y0] = x0;
}
模板-并查集
最新推荐文章于 2020-05-19 23:08:28 发布