UnionFind implementation using Quick-find and Quick-union algorithms