11 std::vector<int> parent;
12 std::vector<int> rank;
20 explicit DisjointSet(
int size) : parent(size), rank(size, 0), count(size)
22 for (
int i = 0; i < size; ++i)
37 parent[p] =
find(parent[p]);
56 if (rank[rootP] < rank[rootQ])
58 parent[rootP] = rootQ;
60 else if (rank[rootP] > rank[rootQ])
62 parent[rootQ] = rootP;
66 parent[rootQ] = rootP;
Definition disjoint_set.hpp:9
DisjointSet(int size)
Construct a new Disjoint Set object.
Definition disjoint_set.hpp:20
int find(int p)
Find the set containing element 'p'.
Definition disjoint_set.hpp:33
int getCount() const
Get the number of distinct sets.
Definition disjoint_set.hpp:77
void unionSets(int p, int q)
Union the sets containing elements 'p' and 'q'.
Definition disjoint_set.hpp:47
Definition big_integer.hpp:14