[C++] Simple C++ Code
\n# If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.\n\nclass Solution {\n    v
\n# **If you like the implementation then Please help me by increasing my reputation. By clicking the up arrow on the left of my image.**\n```\nclass Solution {\n    vector<int> alice, bob;\n    static bool comp(vector<int> &a, vector<int> &b)\n    {\n        return a[0] > b[0];\n    }\n    int find_alice(int v)\n    {\n        if(v == alice[v])\n            return v;\n        return alice[v] = find_alice(alice[v]);\n    }\n    int find_bob(int v)\n    {\n        if(v == bob[v])\n            return v;\n        return bob[v] = find_bob(bob[v]);\n    }\n    void union_alice(int a, int b)\n    {\n        a = find_alice(a);\n        b = find_alice(b);\n        if(a == b)\n            return;\n        alice[b] = a;\n        return;\n    }\n    void union_bob(int a, int b)\n    {\n        a = find_bob(a);\n        b = find_bob(b);\n        if(a == b)\n            return;\n        bob[b] = a;\n        return;\n    }\npublic:\n    int maxNumEdgesToRemove(int n, vector<vector<int>>& edges) {\n        sort(edges.begin(), edges.end(), comp);\n        for(int i = 0; i <= n; i++)\n        {\n            alice.push_back(i);\n            bob.push_back(i);\n        }\n        int ans = 0;\n        for(vector<int> &v : edges)\n        {\n            if(v[0] == 3)\n            {\n                int xa = find_alice(v[1]);\n                int ya = find_alice(v[2]);\n                int xb = find_bob(v[1]);\n                int yb = find_bob(v[2]);\n                if(xa == ya && xb == yb)\n                {\n                    ans++;\n                }\n                else\n                {\n                    if(xa != ya)\n                        union_alice(xa, ya);\n                    if(xb != yb)\n                        union_bob(xb, yb);\n                }\n            }\n            else if(v[0] == 2)\n            {\n                int xb = find_bob(v[1]);\n                int yb = find_bob(v[2]);\n                if(xb == yb)\n                    ans++;\n                else\n                {\n                    union_bob(xb, yb);\n                }\n            }\n            else\n            {\n                int xa = find_alice(v[1]);\n                int ya = find_alice(v[2]);\n                if(xa == ya)\n                    ans++;\n                else\n                    union_alice(xa, ya);\n            }\n        }\n        int vala, valb;\n        for(int i = 1; i <= n; i++)\n        {\n            if(i == 1)\n            {\n                vala = find_alice(i);\n                valb = find_bob(i);\n            }\n            else\n            {\n                if(vala != find_alice(i))\n                {\n                    return -1;\n                }\n                if(valb != find_bob(i))\n                {\n                    return -1;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Union Find', 'Graph', 'C', 'C++']