python union find, beat 100%
python\nclass Solution:\n    def minMalwareSpread(self, graph, initial):\n        N = len(graph)\n        clean = list(set(range(N)) - set(initial))\n        pa
```python\nclass Solution:\n    def minMalwareSpread(self, graph, initial):\n        N = len(graph)\n        clean = list(set(range(N)) - set(initial))\n        parents, size = list(range(N)), [1] * N\n        \n        def find(a):\n            while parents[a] != a:\n                parents[a] = parents[parents[a]]\n                a = parents[a]\n            return a\n        \n        def union(a, b):\n            ra, rb = find(a), find(b)\n            if ra != rb:\n                if size[ra] > size[rb]:\n                    parents[rb] = ra\n                    size[ra] += size[rb]\n                else:\n                    parents[ra] = rb\n                    size[rb] += size[ra]\n                    \n        for u, v in itertools.combinations(clean, 2):\n            if graph[u][v]: union(u, v)\n                \n        infect_node, infected_by, max, res = collections.defaultdict(set), collections.Counter(), -1, min(initial)\n        \n        for u in initial:\n            for v in clean:\n                if graph[u][v]:\n                    infect_node[u].add(find(v))\n            for i in infect_node[u]:\n                infected_by[i] += 1\n                \n        for i, nodes in infect_node.items():\n            count = 0\n            for node in nodes:\n                if infected_by[node] == 1: count += size[node]\n            if count > max or count == max and i < res:\n                max, res = count, i\n        return res\n```
[]