int pre[N];int fnd(int x){ int r=x; while(pre[r]!=r) r=pre[r]; int i=x,j; while(i!=r) { j=pre[i]; pre[i]=r; i=j; } return r;}void join(int x,int y){ x=fnd(x),y=fnd(y); if(x!=y) pre[x]=y;}
本文共 300 字,大约阅读时间需要 1 分钟。
int pre[N];int fnd(int x){ int r=x; while(pre[r]!=r) r=pre[r]; int i=x,j; while(i!=r) { j=pre[i]; pre[i]=r; i=j; } return r;}void join(int x,int y){ x=fnd(x),y=fnd(y); if(x!=y) pre[x]=y;}
转载于:https://www.cnblogs.com/d-e-v-i-l/p/4782872.html