Python Union Find Solution
As mentioned in many other solutions, the main idea is that we want to construct the graph from given edges rather than removing edges. \nYou need to argue and 
As mentioned in many other solutions, the main idea is that we want to construct the graph from given edges rather than removing edges. \nYou need to argue and make yourself belive that it is always optimal to take blue colored edges and connect a red/green edge only if they aren\'t already connected ( part of same connected set), this is where the concept of DSU( Disjoing Set Union) comes in .\nBelow is the code.\n\n```\nclass UnionFind:\n    def __init__(self, n):\n        self.parent = [i for i in range(n + 1)]\n        self.size = [1 for _ in range(n + 1)]\n        self.count = n\n    \n    def find(self, x):\n        if self.parent[x] == x:\n            return x\n        self.parent[x] = self.find(self.parent[x])\n        return self.parent[x]\n\n    def merge(self, a, b):\n        pa = self.find(a)\n        pb = self.find(b)\n        if pa == pb:\n            return False\n        if self.size[pa]> self.size[pb]:\n            self.size[pa] += self.size[pb]\n            self.parent[pb] = pa\n        else:\n            self.size[pb] += self.size[pa]\n            self.parent[pa] = pb\n\n        return True\n    \nclass Solution:\n    def maxNumEdgesToRemove(self, n: int, edges: List[List[int]]) -> int:\n        ufa = UnionFind(n)\n        ufb = UnionFind(n)\n        cnta = 0\n        common = 0\n        \n        for edge in edges:\n            if edge[0] == 3:\n                if ufa.find(edge[1]) != ufa.find(edge[2]):\n                    ufa.merge(edge[1], edge[2])\n                    common += 1\n                    cnta += 1\n        \n        for edge in edges:\n            if edge[0] == 1:\n                if ufa.find(edge[1])!=ufa.find(edge[2]):\n                    ufa.merge(edge[1], edge[2])\n                    cnta += 1\n        \n        \n        if cnta != n-1:\n            return -1\n        \n        cntb = 0\n        for edge in edges:\n            if edge[0] == 3:\n                if ufb.find(edge[1])!=ufb.find(edge[2]):\n                    ufb.merge(edge[1], edge[2])\n        \n        for edge in edges:\n            if edge[0] == 2:\n                if ufb.find(edge[1])!=ufb.find(edge[2]):\n                    ufb.merge(edge[1], edge[2])\n                    cntb += 1\n        \n        \n        if cntb  + common != n-1:\n            return -1\n        \n        \n        total = len(edges)\n        print(total)\n        return total - (cnta + cntb) \n```
['Union Find', 'Graph', 'Python3']