finalized disjoint sets in 2d matrix algorithm