Implementation of quick union with path compression