DisjointSetUnion class
#include <gtopt/bus_island.hpp>
Disjoint Set Union (Union-Find) with path compression and union by rank.
Each element is identified by a contiguous index in [0, n). All operations are amortised O(α(n)) ≈ O(1).
Constructors, destructors, conversion operators
- DisjointSetUnion(std::size_t n) explicit
- Construct a DSU with
nsingleton sets.
Public functions
Function documentation
bool gtopt:: DisjointSetUnion:: unite(std::size_t x,
std::size_t y)
| Returns | true if the two sets were different (and have been merged). |
|---|
Merge the sets containing x and y.