Add custom disjoint-set implementation