modified UnionFind