WeightedQuickUnion algorithm