vector<uint64_t>
depth;
45 explicit dsu(uint64_t n) {
50 for(uint64_t i = 0; i < n; i++) {
121vector<uint64_t> ans;
122 while(
p[i] != i) {
147vector<uint64_t> ans = {7, 5};
148 for(uint64_t i = 0; i < ans.size(); i++) {
152cout <<
"1st test passed!"<<
endl;
172vector<uint64_t> ans = {2, 1, 10};
173 for(uint64_t i = 0; i < ans.size(); i++) {
177cout <<
"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.
int main()
Main function.
static void test1()
Self-implementations, 1st test.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4