BFS solution
Intuition\n Describe your first thoughts on how to solve this problem. \nCalculate the total number of infected nodes for each node that we want to remove, and 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCalculate the total number of infected nodes for each node that we want to remove, and get the minimum result.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n^3)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\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        n = len(graph)\n        edges = defaultdict(list)\n        for i in range(n):\n            for j in range(n):\n                if i != j and graph[i][j] == 1:\n                    edges[i].append(j)\n                    edges[j].append(i)\n        initial.sort()\n\n        def bfs(nodeToRemove):\n            infected = set()\n            for node in initial:\n                if node != nodeToRemove:\n                    infected.add(node)\n                    queue = deque([node])\n                    while queue:\n                        curr = queue.popleft()\n                        for next in edges[curr]:\n                            if next not in infected and next != nodeToRemove:\n                                infected.add(next)\n                                queue.append(next)\n            return len(infected)\n\n\n\n\n        minInfection = n + 1\n        candidate = None\n        for node in initial:\n            result = bfs(node)\n            if result < minInfection:\n                minInfection = result\n                candidate = node\n        return candidate\n\n```
['Python3']