Added path compression to UnionFind data structure