DSU c++ explained by comments
\n\n\nclass Solution {\npublic:\n\n    int alice[100001];\n    int bob[100001];\n  \nint finda(int a){\n\tif(alice[a]==-1)\n\treturn a;\n\treturn alice[a]=finda
```\n\n\nclass Solution {\npublic:\n\n    int alice[100001];\n    int bob[100001];\n  \nint finda(int a){\n\tif(alice[a]==-1)\n\treturn a;\n\treturn alice[a]=finda(alice[a]);\n}\n    int findb(int a){\n\tif(bob[a]==-1)\n\treturn a;\n\treturn bob[a]=findb(bob[a]);\n}\nvoid mergea (int a,int b){\n\talice[a]=b;\n}\n    void mergeb (int a,int b){\n\tbob[a]=b;\n}\n    int maxNumEdgesToRemove(int n, vector<vector<int>>& edges) {\n        for(int i=0;i<100001;i++){\n\talice[i]=-1;\n            bob[i]=-1;\n}   \n     int t3=0;//essential edges for both \n        for(int i=0;i<edges.size();i++){\n            if(edges[i][0]==3){\n                if(finda(edges[i][1])!=finda(edges[i][2])){\n                   mergea(finda(edges[i][1]),finda(edges[i][2]));\n                   mergeb(findb(edges[i][1]),findb(edges[i][2]));\n                    t3++;\n                }\n            }\n        }\n        int t1=0; // essential edges for alice\n         for(int i=0;i<edges.size();i++){\n            if(edges[i][0]==1){\n                if(finda(edges[i][1])!=finda(edges[i][2])){\n                    mergea(finda(edges[i][1]),finda(edges[i][2]));\n                    \n                    t1++;\n                    cout<<"I"<<i<<" ";\n                }\n            }\n        }\n        int t2=0; //essential edges for bob\n         for(int i=0;i<edges.size();i++){\n            if(edges[i][0]==2){\n                if(findb(edges[i][1])!=findb(edges[i][2])){\n                    mergeb(findb(edges[i][1]),findb(edges[i][2]));\n                    \n                    t2++;\n                }\n            }\n        }\n   if(t1+t3<n-1||t3+t2<n-1)// if(t1+t3<n-1) then alice can not traverse the graph because tree requires n-1 edges to be spanned completely if(t2+t3<n-1)then bob can not traverse.\n       return -1;\n        \n        cout<<t1<<" "<<t2<<" "<<t3<<endl;\n      return edges.size()-t1-t2-t3;  //(t1+t2+t3) are essential edges\n    }\n};\n\n\n// below description in hindi vvvvvvvvvvvvvvvvvvvvvv//\n\n// yrrr agar yeh code smjhna he toh bsss sbse phle type third nodes count krrro jo essential he unse alice ka parent  array aur bob ka parent  array dono modify honge but in case of type 1 node we only modify alice array in second for loop then we run last loop for bob \n// so t1 +t2+t3 are all the essential edgess we can get \n//so answer is total -(essential);------------------:)\n\n\n```
[]