add Tree and UnionFind classes