C++ | Union-Find | Code and Steps|Hinglish
I am writing the steps in both English and Hinglish because I personally feel Hinglish makes it easier to understand for native Hindi speakers.\nSteps:-\n Make 
I am writing the steps in both English and Hinglish because I personally feel Hinglish makes it easier to understand for native Hindi speakers.\nSteps:-\n* Make all the components which you can reach from type 3 edges i.e traverserable for both Alice and Bob.(Sabse pehle saare components nikallo 3rd type ki edge use karke ,jisko Alice and Bob dono use kar sake).\n* Now using First go with alice and find if we can connect all the disconnected groups using the Alice edges.(uske baad yeh dekho ki kyaa alice apne edges use karke saare jagah jaa sakta hai ,toh isse humhe alice ke minimum required edges aajayenge).\n* And apply same for Bob.(Bob ke liye bhi check karlo)\n* Final answer will be \n\t*if(alice edges!=n-1 || bob edges!=-1){\n\t\tthen all the edges cannot be traversed.(Matlab Alice Bob nhi kar sakte saare destinations.)\n\t\treturn -1.\n\t}\n\totherwise (varna)\n\ttotaledges-(alice edges+bob edges-common edges(because we have added common edges with both alice and bob));(saare edges mein se alice ki requirement+bob ki requirement aur inmein se common edges jo 2 baar add hue hai unko total edges mein se subtract kardo.)\n\n\n\n\nclass Solution {\npublic:\n   \n    \n    int findp(int x, vector<int> &par){\n        if(par[x]!=x){\n            par[x]=findp(par[x],par);\n        }\n        return par[x];\n    }\n    void unio(int x,int y, vector<int> &par){\n        int p1=findp(x,par);\n        int p2=findp(y,par);\n        if(p1!=p2){\n            par[p2]=p1;\n        }\n    }\n    \n    \n    int maxNumEdgesToRemove(int n, vector<vector<int>>& edges) {\n        unordered_map<int,vector<int>> gA;\n        unordered_map<int,vector<int>> gB;\n        unordered_map<int,vector<int>> gC;\n        \n        for(auto r:edges){\n            if(r[0]==1){\n                gA[r[1]].push_back(r[2]);\n                gA[r[2]].push_back(r[1]);\n            }else if(r[0]==2){\n                gB[r[1]].push_back(r[2]);\n                gB[r[2]].push_back(r[1]);\n            }else{\n                gC[r[1]].push_back(r[2]);\n                gC[r[2]].push_back(r[1]);\n            }\n        }\n        vector<int> par;\n        par.resize(n+1,0);\n        for(int i=1;i<=n;i++){\n            par[i]=i;\n        }\n        \n        int ed=0;\n        int cnt=0;\n        \n        \n        \n        for(int i=1;i<=n;i++){\n            for(int j:gC[i]){\n                int p1=findp(i,par);\n                int p2=findp(j,par);\n                if(p1==p2){\n                    continue;\n                }else{\n                    unio(i,j,par);\n                    ed++;\n                }\n            }\n        }\n       \n        vector<int> pa=par;\n        vector<int> pb=par;\n        int ed1=ed;\n        int ed2=ed;\n        for(int i=1;i<=n;i++){\n            int p1=findp(i,pa);\n           \n            for(auto j:gA[i]){\n                int p2=findp(j,pa);\n                if(p1==p2){\n                    continue;\n                }else{\n                    unio(i,j,pa);\n                    ed1++;\n                }\n            }\n            int p4=findp(i,pb);\n             for(auto k:gB[i]){\n                int p3=findp(k,pb);\n                if(p4==p3){\n                    continue;\n                }else{\n                    unio(i,k,pb);\n                    ed2++;\n                }\n            }\n        }\n     \n        \n        if(ed1!=n-1 || ed2!=n-1 ){\n            return -1;\n        }\n        return edges.size()-(ed1+ed2-ed);\n       \n    }\n};
['Union Find', 'C']