1.集:集合;并:合并;查:查找
2.并查集是解决集合的合并和查找问题
3.主要函数
#include<bits/stdc++.h>
using namespace std;
#define N 1000
int father[N];
void init();
{
for(int i=1;i<=N;i++)
{
father[i]=i;
}
}
int find(int x)
{
if(father[x]==x)
{
return x;
}
else
{
return father[x]=find(father[x]);
}
}
void Union(int x, int y)
{
x=find(x);
y=find(y);
if(x!=y)
{
father[x]=y;
}
}
int main()
{
return 0;
}