Modified Union find data structure