Java BFS answer from Minimize Malware Spread I
Original code: https://leetcode.com/problems/minimize-malware-spread/discuss/181116/Java-BFS For every infected node, we remove the candidate from the list of n
Original code: https://leetcode.com/problems/minimize-malware-spread/discuss/181116/Java-BFS
For every infected node, we remove the candidate from the list of nodes that are affected.  During our bfs to search how far the infection spread we ignore all edges that contain the removed infection's node by skipping (continueing) if we encounter it. And search normally.  We repeat the proceess until we've tried removing then one by one. And we take the minimum amount and minimum id to break ties.  Then we return the node that was found.
```
class Solution {
    private int spread(int [][] graph, Set<Integer> infected, int removed){
        Set<Integer> bad = new HashSet<>(infected);
        Queue<Integer> bfs= new LinkedList<>();
        for(Integer initialInfected:infected){
            bfs.add(initialInfected);
        }
        while(!bfs.isEmpty()){
            Integer next = bfs.remove();
            if(next==removed)continue;
            for(int j=0; j<graph[next].length;++j){
                if(j==removed)continue;
                if(graph[next][j]==1&& !bad.contains(j)){
                    bad.add(j);
                    bfs.add(j);
                }
            }
        }
        //return how many were infected
        return bad.size();
    }
    public int minMalwareSpread(int[][] graph, int[] initial) {
        Set<Integer> infected = new HashSet<>();
        for(int initialInfected: initial){
            infected.add(initialInfected);
        }
        int min = Integer.MAX_VALUE;
        int ans = 0;
        for(int ignore = 0; ignore<initial.length;++ignore){
            int ignoreNumb = initial[ignore];
            infected.remove(ignoreNumb);
            int amount = spread(graph,infected, ignoreNumb);
            if(amount<min ||(amount==min&& initial[ignore]<ans)){
                ans=initial[ignore];
                min=amount;
            }
            infected.add(ignoreNumb);
        }
        return ans;
    }
}
```
[]