题目链接:1319: 球 参考:wustoj 1319 球-wust_tanyao,并查集 并查集系列:WUSTOJ 1346: DARK SOULS(Java)并查集 Description Icy is a lonely boy. He was so boring these days. So he started to play a game himself. First, he took a heap of balls with many different colors. ( One
Java实现并查集,合并时采用路径压缩算法. 如果合并时使用循环修改的方法,一次合并的时间复杂度就为N,无法接受 public class Union { public int[] id;//对应索引所在的集 public int[] sz;//所在集的size,合并时小集合大集 public int count; public Union(int N){ id = new int[N]; for(int i=0;i<id.length;i++){ id[i] = i; } }//初始化,每个节