Easy C++ Video Explanation
Video Explanation\nhttps://youtu.be/PmdyES1mtAw?si=b1KX0ivnRLEOq-Qg\n# Complexity\n\n- Time complexity:O(E *logE) \n Add your time complexity here, e.g. O(n) \n
# Video Explanation\nhttps://youtu.be/PmdyES1mtAw?si=b1KX0ivnRLEOq-Qg\n# Complexity\n\n- Time complexity:$$O(E *logE)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(N+E)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nE is the number of edges\n\n# Code\n```\nclass Solution {\n    bool static comp(vector<int>& a, vector<int>& b) { return a[0] > b[0]; }\n    int findparent(int node, vector<int>& parent) {\n        if (node == parent[node])\n            return node;\n        return parent[node] = findparent(parent[node], parent);\n    }\n    bool unionn(int u, int v, vector<int>& parent, vector<int>& rank) {\n        u = findparent(u, parent);\n        v = findparent(v, parent);\n\n        if (u != v) {\n            if (rank[u] < rank[v])\n                parent[u] = v;\n            else if (rank[u] > rank[v])\n                parent[v] = u;\n            else {\n                parent[v] = u;\n                rank[u]++;\n            }\n            return true;\n        }\n        return false;\n    }\npublic:\n   \n    int maxNumEdgesToRemove(int n, vector<vector<int>>& edges) {\n        vector<int>parent_alice(n+1);\n        vector<int>parent_bob(n+1);\n        vector<int>alice_rank(n+1);\n        vector<int>bob_rank(n+1);\n\n        sort(edges.begin(),edges.end(),comp);\n\n        for(int i=0;i<parent_alice.size();i++){\n            parent_alice[i]=i;\n            parent_bob[i]=i;\n            alice_rank[i]=1;\n            bob_rank[i]=1;\n        }\n        int remove_edges=0;\n        int merge_alice=1;\n        int merge_bob=1;\n        for(auto it:edges){\n            if(it[0]==3){\n                bool temp_alice=unionn(it[1],it[2],parent_alice,alice_rank);\n                bool temp_bob=unionn(it[1],it[2],parent_bob,bob_rank);\n\n                if(temp_alice==true){\n                    merge_alice++;\n                }\n                if(temp_bob==true){\n                    merge_bob++;\n                }\n                if(temp_alice==false && temp_bob==false){\n                    remove_edges++;\n                }\n            }else if(it[0]==1){\n                bool temp_alice=unionn(it[1],it[2],parent_alice,alice_rank);\n                if(temp_alice==true){\n                    merge_alice++;\n                }else{\n                    remove_edges++;\n                }\n            }else{\n                bool temp_bob=unionn(it[1],it[2],parent_bob,bob_rank);\n                if(temp_bob==true){\n                    merge_bob++;\n                }\n                else{\n                    remove_edges++;\n                }\n            }\n\n        }\n        if(merge_alice!=n || merge_bob!=n) return -1;\n        return remove_edges;\n    }\n};\n```
['C++']