Path compression with successors and predecessors