10
for (int i = 0; i < n; i++) {18
// if parent of node is itself19
if (parent[node] == node) {22
return parent[node] = Find(parent[node]);26
void Union(int u, int v) {27
// find the parent nodes of u and v31
// if u and v don't belong to the same set33
if (rank[u] < rank[v]) {37
// attaching the lower rank tree with the higher rank one40
// if ranks are equal increase the rank of u41
if (rank[u] == rank[v]) {50
vector<int> findRedundantConnection(vector<vector<int>> &edges) {51
UnionFind UF = UnionFind(1001);53
for (vector<int> &edge : edges) {57
// if adding this edge creates a cycle58
if (UF.Find(u) == UF.Find(v)) {62
// add u and v to the same set66
// if no cycle was found