Java Solution BFS
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 Solution {\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        Map<Integer, List<Integer>> map = new HashMap<>();\n        for(int i = 0; i < graph.length; i++){\n            for(int j = i + 1; j < graph[0].length; j++){\n                if(graph[i][j] == 1){\n                    map.putIfAbsent(i, new ArrayList<>());\n                    map.get(i).add(j);\n                    map.putIfAbsent(j, new ArrayList<>());\n                    map.get(j).add(i);\n                }\n            }\n        }\n        Map<Integer, List<Integer>> node_to_source = new HashMap<>();\n        TreeSet<Integer> initials = new TreeSet<>();\n        for(int i : initial){\n            initials.add(i);\n        }\n        for(int start : initial){\n            helper(start, node_to_source, map, initials);\n        }\n        Map<Integer, Integer> source_affect_node = new HashMap<>();\n        for(Map.Entry<Integer, List<Integer>> entry : node_to_source.entrySet()){\n            int node = entry.getKey();\n            List<Integer> sources = entry.getValue();\n            if(sources.size() == 1){\n                int source = sources.get(0);\n                source_affect_node.putIfAbsent(source, 0);\n                source_affect_node.put(source, source_affect_node.get(source) + 1);\n            }\n        }\n        int removed_source = -1;\n        int count = -1;\n        for(Map.Entry<Integer, Integer> entry : source_affect_node.entrySet()){\n            int source = entry.getKey();\n            int num_node_affected = entry.getValue();\n            if(count < num_node_affected){\n                removed_source = source;\n                count = num_node_affected;\n            }\n            else if(count == num_node_affected && source < removed_source){\n                removed_source = source;\n            }\n        }\n        if(removed_source == -1){\n            Arrays.sort(initial);\n            return initial[0];\n        }\n        return removed_source;\n    }\n    private void helper(int start, Map<Integer, List<Integer>> node_to_source, Map<Integer, List<Integer>> map, TreeSet<Integer> initials){\n        Queue<Pair<Integer, Integer>> queue = new ArrayDeque<>();\n        Set<Integer> visited = new HashSet<>();\n        queue.offer(new Pair<>(start, start));\n        while(!queue.isEmpty()){\n            Pair<Integer, Integer> current = queue.poll();\n            int current_node = current.getKey();\n            int source = current.getValue();\n            List<Integer> neighbors = map.get(current_node);\n            if(neighbors == null){\n                continue;\n            }\n            for(int nei : neighbors){\n                if(visited.add(nei) && !initials.contains(nei)){\n                    queue.offer(new Pair<>(nei, source));\n                    node_to_source.putIfAbsent(nei, new ArrayList<>());\n                    node_to_source.get(nei).add(source);\n                }\n            }\n        }\n    }\n}\n```
['Java']