Union find and merge sort