Disjoint set data structure with path compression