Weighted quick union UnionFind implementation