modified UnionFind.cc