Implementation of the UnionFind data structure