disjoint_sets uses heap instaed of stack