Union-Find | Cycle-detection | C++ Solution
Algorithm\n1. The edge wich joins nodes of same set is a redundent edge\n\nclass DisjointSet {\n    vector<int> parent, size;\npublic:\n    DisjointSet(int n) {
**Algorithm**\n1. The edge wich joins nodes of same set is a redundent edge\n```\nclass DisjointSet {\n    vector<int> parent, size;\npublic:\n    DisjointSet(int n) {\n        parent.resize(n + 1);\n        size.resize(n + 1);\n        for (int i = 0; i <= n; i++) {\n            parent[i] = i;\n            size[i] = 1;\n        }\n    }\n\n    int find(int node) {\n        if (node == parent[node])\n            return node;\n        return parent[node] = find(parent[node]);\n    }\n    bool unionBySize(int u, int v) {\n        int ulp_u = find(u);\n        int ulp_v = find(v);\n        if (ulp_u == ulp_v) return false;\n        if (size[ulp_u] < size[ulp_v]) {\n            parent[ulp_u] = ulp_v;\n            size[ulp_v] += size[ulp_u];\n        }\n        else {\n            parent[ulp_v] = ulp_u;\n            size[ulp_u] += size[ulp_v];\n        }\n        return true;\n    }\n};\nclass Solution {\npublic:\n    vector<int> findRedundantConnection(vector<vector<int>>& edges) {\n        int mx=edges.size();\n        DisjointSet ds(mx);\n        for(auto &edge:edges){\n            int u=edge[0];int v=edge[1];\n            if(!ds.unionBySize(u,v)){\n                return {u,v};\n            }\n        }\n        return {-1,-1};\n    }\n};\n```
['Union Find', 'C']