int find(int x){return x==F[x]?x:find(F[x]);} void join(int x,int y){ int fx=find(x); int fy=find(y); if(fx!=fy){ F[fy]=fx; rank[fx]+=rank[fy];// 子节点数量 } }
并查集
原文:http://blog.51cto.com/14093713/2323474