Implements Union-Find (aka disjoint-sets) data structure.