Best C++ Code...
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n- The time complexity of this approach is O(E), where E is the number of edges, as we are using path compression and union by rank so the find and union function become O(1) on average.\n\n- Space complexity:\nThe space complexity is also O(N), where N is the number of nodes\n\n# Code\n```\nclass Solution {\npublic:\n    int find(int i,vector<int> &par){\n        if(par[i] == -1){\n            return i;\n        }\n        return par[i] = find(par[i],par);\n        //path compression.\n    }\n    bool union_set(int x,int y,vector<int> &par,vector<int> &rnk){\n        int s1 = find(x,par);\n        int s2 = find(y,par);\n        \n        if(s1 != s2){\n            //union by rank.\n            if(rnk[s1] > rnk[s2]){\n                par[s2] = s1;\n                rnk[s1] += rnk[s2];\n            }\n            else{\n                par[s1] = s2;\n                rnk[s2] += rnk[s1];\n            }\n            return true;\n        }\n        return false;\n    }\n    int maxNumEdgesToRemove(int n, vector<vector<int>>& edges) {\n        \n        sort(edges.begin(),edges.end(),[](vector<int> &a,vector<int> &b){\n            return a[0] > b[0]; \n        });\n        // To process the edges of type 3 first we sort the edges vector.\n        \n        int rem = 0;\n        \n        vector<int> parAlice(n,-1);\n        vector<int> parBob(n,-1);\n        vector<int> rnkAlice(n,1);\n        vector<int> rnkBob(n,1);\n        \n        for(int i=0;i<edges.size();i++){\n            if(edges[i][0] == 3){\n                bool fg1 = union_set(edges[i][1]-1,edges[i][2]-1,parAlice,rnkAlice);\n                bool fg2 = union_set(edges[i][1]-1,edges[i][2]-1,parBob,rnkBob);\n                if(fg1==false && fg2==false){\n                    //alice and bob are both connected to node x and node y so remove this edge.\n                    rem += 1;\n                }\n            }\n            else if(edges[i][0] == 2){\n                bool fg2 = union_set(edges[i][1]-1,edges[i][2]-1,parBob,rnkBob);\n                if(fg2 == false){\n                    //bob is connected to node x and node y so remove this edge.\n                    rem += 1;\n                }\n            }\n            else{\n                bool fg1 = union_set(edges[i][1]-1,edges[i][2]-1,parAlice,rnkAlice);\n                if(fg1 == false){\n                    //alice is connected to node x and node y so remove this edge.\n                    rem += 1;\n                }\n            }\n        }\n        \n        int co1=0,co2=0;\n        for(int i=0;i<n;i++){\n            if(parAlice[i]==-1){co1++;}\n            if(parBob[i]==-1){co2++;}\n            //if the nodes can be connected then there will be only one parent in the parent array.\n        }\n        if(co1==1 && co2==1){return rem;}\n        return -1;\n    }\n};\n\n```
['C++']