38 vector<uint64_t>
depth;
45 explicit dsu(uint64_t n) {
50 for (uint64_t i = 0; i < n; i++) {
121 vector<uint64_t> ans;
147 vector<uint64_t> ans = {7, 5};
148 for (uint64_t i = 0; i < ans.size(); i++) {
152 cout <<
"1st test passed!" <<
endl;
172 vector<uint64_t> ans = {2, 1, 10};
173 for (uint64_t i = 0; i < ans.size(); i++) {
177 cout <<
"2nd test passed!" <<
endl;
Disjoint sets union data structure, class based representation.
dsu(uint64_t n)
constructor for initialising all data members
uint64_t findSet(uint64_t i)
Method to find the representative of the set to which i belongs to, T(n) = O(logN)
vector< uint64_t > p
keeps track of the parent of ith element
vector< uint64_t > depth
tracks the depth(rank) of i in the tree
bool isSame(uint64_t i, uint64_t j)
A utility function which check whether i and j belongs to same set or not.
void unionSet(uint64_t i, uint64_t j)
Method that combines two disjoint sets to which i and j belongs to and make a single set having a com...
vector< uint64_t > getParents(uint64_t i)
Method to print all the parents of i, or the path from i to representative.
vector< uint64_t > setSize
size of each chunk(set)
static void test2()
Self-implementations, 2nd test.
static void test1()
Self-implementations, 1st test.