[c++][runtime beats 98.89 %][union find]
\nclass Solution {\npublic:\n    int find(int x, vector<int>& parents) {\n        return parents[x] == x ? x : find(parents[x], parents);\n    }\n    vector<int
```\nclass Solution {\npublic:\n    int find(int x, vector<int>& parents) {\n        return parents[x] == x ? x : find(parents[x], parents);\n    }\n    vector<int> findRedundantConnection(vector<vector<int>>& edges) {\n        vector<int> res(edges.size()+1);\n        for(int i=1;i<edges.size()+1;i++) res[i]=i;\n        vector<int> ans;\n        for(auto edge: edges){\n            int a1=find(edge[0],res);\n            int a2=find(edge[1],res);\n            if(a1!=a2) res[a1]=a2;\n            else ans={edge[0],edge[1]};\n        }\n        return ans;\n    }\n};\n```\n**Feel free to ask any question in the comment section.**\nI hope that you\'ve found the solution useful.\nIn that case, **please do upvote and encourage me** to on my quest to document all leetcode problems\uD83D\uDE03\nHappy Coding :)\n
['Union Find', 'C', 'C++']