11 vector<int32_t> *fa = NULL;
13 uint32_t getfa(
int i) {
14 if ((*fa)[i] < 0) (*fa)[i] = i;
16 (*fa)[i] = getfa((*fa)[i]);
25 void setLength(
int n) {
27 fa =
new vector<int32_t> (n,-1);
29 fa->resize(0); fa->resize(n,-1); }
36 void merge(
int a,
int b) {
38 (*fa)[getfa(b)] = getfa(a);
40 bool sameset(
int a,
int b) {
41 return getfa(a)==getfa(b);
bool resize(int n)
add new keys, so that the total number of elements equal to n.
Definition: disjointset.h:47
void finish()
Release the memory to save some space.
Definition: disjointset.h:20
void clear()
re-initilize the disjoint sets.
Definition: disjointset.h:32
Disjoint Set data structure. Helps to test the acyclicity of the graph during construction.
Definition: disjointset.h:10