Beats 93% users... Give my code a try and get accurate result
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass UnionFind:\n\n    """A minimalist standalone union-find implementation."""\n\n    def __init__(self, n):\n\n        self.count = n               # number of disjoint sets \n\n        self.parent = list(range(n)) # parent of given nodes\n\n        self.rank = [1]*n            # rank (aka size) of sub-tree \n\n        \n\n    def find(self, p):\n\n        """Find with path compression."""\n\n        if p != self.parent[p]: \n\n            self.parent[p] = self.find(self.parent[p]) # path compression \n\n        return self.parent[p]\n\n    \n\n    def union(self, p, q):\n\n        """Union with ranking."""\n\n        prt, qrt = self.find(p), self.find(q)\n\n        if prt == qrt: return False\n\n        self.count -= 1 # one more connection => one less disjoint \n\n        if self.rank[prt] > self.rank[qrt]: prt, qrt = qrt, prt # add small sub-tree to large sub-tree for balancing\n\n        self.parent[prt] = qrt\n\n        self.rank[qrt] += self.rank[prt] # ranking \n\n        return True\n\n    \n\n        \n\nclass Solution:\n\n    def maxNumEdgesToRemove(self, n: int, edges: List[List[int]]) -> int:\n\n        ufa = UnionFind(n) # for Alice\n\n        ufb = UnionFind(n) # for Bob\n\n        \n\n        ans = 0\n\n        edges.sort(reverse=True) \n\n        for t, u, v in edges: \n\n            u, v = u-1, v-1\n\n            if t == 3: ans += not (ufa.union(u, v) and ufb.union(u, v)) # Alice & Bob\n\n            elif t == 2: ans += not ufb.union(u, v)                     # Bob only\n\n            else: ans += not ufa.union(u, v)                            # Alice only\n\n        return ans if ufa.count == 1 and ufb.count == 1 else -1 # check if uf is connected \n\n        \n```
['Union Find', 'Graph', 'C', 'C++', 'Java', 'Python3', 'JavaScript']