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; }
posted on 2015-09-05 10:39 恶devil魔 阅读(114) 评论(0) 编辑 收藏 举报
Powered by: 博客园 Copyright © 2024 恶devil魔 Powered by .NET 9.0 on Kubernetes