Union Find algorithm for disjoint set (并查集算法)
Mainly need to implement two functions `Union` and `Find`, then it is pretty straight forward to use these two functions to get the number of clusters or find the redundant edges etc. (1) 684 Redundant Connection class Solution { public: vector<int> parent; vector<int> rank; int Find(int x) { if (x != parent[x]) // return Find(parent[x]); // Non optimized version parent[x] = Find(parent[x]); // Optimized version. Flatten the tree while finding // Please note you cannot just return x instead, assuming x is always equal to parent[x]. // It is possible that x == parent[x] in the first recursion. But the recursion call return // value will update the global va...