首页 > 代码库 > 并查集模板

并查集模板

const int maxn =  ;int fa[maxn];int fi(int x){    return fa[x]==x?x:fa[x]=fi(fa[x]);}void union(int x,int y){    int fx = fi(x),fy = fi(y);    if(fx != fy) fa[fx] = fy;}bool check(int x,int y){    int fx = fi(x),fy = fi(y);    if(fx == fy) return true;    return false;}

 

并查集模板