Adding some implementation for the UnionFind class