Creates a mutable Union-Find (Disjoint Set Union) data structure using an environment. It implements path compression and union by size for efficient group operations.
Value
unionfind() returns an environment containing the following property and methods:
parentAn integer vector of size
n. A positive value indicates the index of the parent node. A negative value indicates that the node is a root, and its absolute value represents the size of the group.find(x)A function that returns the root index of the group containing
x.unite(x, y)A function that unites the groups containing
xandy. ReturnsTRUEif the groups were successfully united, orFALSEif they were already in the same group.
