Using Disjoint Set
Intuition\n Describe your first thoughts on how to solve this problem. \nSimple disjoint set use kiya hai, uske baad kuch for loops lagaye hai.\nSamajh aaye toh
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimple disjoint set use kiya hai, uske baad kuch for loops lagaye hai.\nSamajh aaye toh bdiya, warna \n\n\n\n\nThank for the view.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nApproch this question like you approch a girl on a date { I dont know how :( }\nAsk her what she wants, in this case she wants that alex and bob should traverse the graph completely after cutting unimportant edges.\nToo much demands. Either we can make seprate MST for both and check for unimportant edges, or we can say "Lets split the bill".\n\nSecond one is better. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\npta nhi bhai, dekhlo tum , shyd O(n) hi hai\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Disjoint:\n    def __init__(self, n):\n        self.rank = [1]*n\n        self.parents = [i for i in range(n)]\n    def find(self, node):\n        if self.parents[node] != node:\n            self.parents[node] = self.find(self.parents[node])\n        return self.parents[node]\n    def union(self, u, v):\n        uset = self.find(u)\n        vset = self.find(v)\n\n        if uset == vset:\n            return \n        if self.rank[uset] < self.rank[vset]:\n            self.parents[uset] = vset\n        elif self.rank[vset] < self.rank[uset]:\n            self.parents[vset] = uset\n        else:\n            self.parents[vset] = uset\n            self.rank[uset] += 1\n\nclass Solution:\n    def maxNumEdgesToRemove(self, n: int, edges: List[List[int]]) -> int:\n        edges3 = []\n        wt1, wt2 = 0, 0\n        ans1 = []\n        ans2 = []\n        ds1 = Disjoint(n+1)\n        ds2 = Disjoint(n+1)\n        for t, i,j in edges:\n            if t==3:\n                edges3.append((i,j))\n        edges3.sort()        \n        for i, j in edges3:\n            ii = ds1.find(i)\n            jj = ds1.find(j)\n            if ii != jj:\n                wt1 += 1\n                ans1.append((3,i,j))\n                ds1.union(i,j)\n        for i, j in edges3:\n            ii = ds2.find(i)\n            jj = ds2.find(j)\n            if ii != jj:\n                wt2 += 1\n                ans2.append((3,i,j))\n                ds2.union(i,j)                \n\n\n        for typee, i, j in edges:\n            if typee == 1 or typee==3:\n                ii = ds1.find(i)\n                jj = ds1.find(j)\n                if ii != jj:\n                    wt1 += 1\n                    ans1.append((typee,i,j))\n                    ds1.union(i,j)\n            if typee == 2 or typee == 3:\n                ii = ds2.find(i)\n                jj = ds2.find(j)\n                if ii != jj:\n                    wt2 +=1\n                    ans2.append((typee,i,j))\n                    ds2.union(i,j)\n        #print(wt1, wt2)            \n        if wt1 != n-1 or wt2 != n-1:\n            return -1\n        #print(ans1)\n        #print(ans2)        \n        a = set(ans1)\n        for it in ans2:\n            a.add(it)\n        return len(edges) - len(a)                    \n\n\n\n        \n```
['Python3']