An efficient implementation of the disjoint-set data structure