Adding weighting to UnionFind.union