[JAVA] Super Straight Forward BFS Solution(Simulation)
BFS Simulation to remove the node and check how many nodes is affected. Not the fatested, just FYI.\n\nclass Solution {\n    public int minMalwareSpread(int[][]
BFS Simulation to remove the node and check how many nodes is affected. Not the fatested, just FYI.\n```\nclass Solution {\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        Arrays.sort(initial);\n        int minSize = Integer.MAX_VALUE;\n        int ans = initial[0];\n        for(int i: initial){\n            int m = bfs(graph, initial, i);\n            if(m < minSize) {minSize = m; ans = i;}\n        }\n        \n        return ans;\n    }\n    \n    //Get all the nodes if remove the one node.\n    private int bfs(int[][] graph, int[] initial, int cut){\n        Queue<Integer> q = new LinkedList<>();\n        for(int i: initial){\n            if(i != cut) q.offer(i);\n        }\n        \n        Set<Integer> seen = new HashSet<>();\n        while(!q.isEmpty()){\n            int sz = q.size();\n            while(sz-->0){\n                int node = q.poll();\n                for(int nei=0;nei<graph[node].length; nei++){\n                    if(nei == cut) continue;//ignore the connections.\n                    if(graph[node][nei]!=1) continue;\n                    if(seen.contains(nei)) continue;\n                    q.offer(nei);\n                    seen.add(nei);\n                }\n            }\n        }\n        \n        return seen.size();\n    }\n}\n```
[]