Cycle detection in undirected graph
\nclass UnionFind {\n  private:\n    vector<int> parent;\n  public:  \n    UnionFind(int n){\n        parent = vector<int>(n+1,-1);\n    }\n    \n    int find(i
```\nclass UnionFind {\n  private:\n    vector<int> parent;\n  public:  \n    UnionFind(int n){\n        parent = vector<int>(n+1,-1);\n    }\n    \n    int find(int x){\n        if(parent[x]==-1) return x;\n        return find(parent[x]);\n    }\n    \n    void Union(int x,int y){\n        int X = find(x);\n        int Y = find(y);\n        parent[X]=Y;\n    }\n    \n};\n\nclass Solution {\npublic:\n    vector<int> findRedundantConnection(vector<vector<int>>& edges) {\n        int n = edges.size();\n        UnionFind *uf = new UnionFind(n);\n            \n        for(auto x:edges){\n            int a = uf->find(x[0]);\n            int b = uf->find(x[1]);\n            if(a==b) return {x[0],x[1]};\n            \n            uf->Union(x[0],x[1]);\n        }\n        return {};\n    }\n};\n```
['Union Find', 'C']