Simple BFS Solution and Pass
Intuition\n Describe your first thoughts on how to solve this problem. \nBFS with each deleted initial values and see how many connected nodes in each connected
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBFS with each deleted initial values and see how many connected nodes in each connected component from supposed deleted initial. Get the smallest connected component. If equal, then get the smallest index of deleted initial.\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 Solution:\n    def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n        # bfs\n\n        def bfs(node):  # bfs with each deleted value\n            queue = deque(initial)\n            visited = set()\n            while queue:\n                cur = queue.popleft()\n                if cur == node or cur in visited:  # ignore deleted initial\n                    continue\n                \n                visited.add(cur)\n                # it will traverse the whole row of cur node\n                for idx, value in enumerate(graph[cur]):           \n                    if value == 1:\n                        queue.append(idx)               \n            return len(visited)  # visited set is malware nodes caused by deleted initial\n\n        min_value = float(\'inf\')\n        connected_component = {}\n        for node in initial:\n            connected_component[node] = bfs(node)\n            min_value = min(min_value, connected_component[node])\n\n        res = []\n        for k, v in connected_component.items():\n            if v == min_value:\n                res.append(k)\n        return min(res)\n  \n```
['Python3']