classSolution { public: int n = 1005; vector<int> father = vector<int>(n, 0); voidinit(){ for (int i = 0; i < n; i++) { father[i] = i; } } intfind(int u){ if (u == father[u]) { return u; } return father[u] = find(father[u]); } boolisSame(int u, int v){ u = find(u); v = find(v); return u == v; } voidjoin(int u, int v){ u = find(u); v = find(v); if (u == v) return; father[v] = u; } vector<int> findRedundantConnection(vector<vector<int>>& edges){ init(); for (int i = 0; i < edges.size(); i++) { if (isSame(edges[i][0], edges[i][1])) return edges[i]; else join(edges[i][0], edges[i][1]); } return {}; } };