数据结构模板之—并查集

1.查询操作

1
2
3
4
5
6
7
8
9
10

int (int x)

{

if(father[x]!=x) father[x]=find2(father[x]);

return father[x];

}

2.更改操作

1
2
3
4
5
6
7

void mergee(int x,int y)
{

father[y]=father[x];

}