Java brute force version
copy a graph everytime and remove the connections, and then count, not efficient, I thought it won\'t ac, but it actually can:)\n(detailed explaination in chine
copy a graph everytime and remove the connections, and then count, not efficient, I thought it won\'t ac, but it actually can:)\n(detailed explaination in chinese http://www.noteanddata.com/leetcode-928-Minimize-Malware-Spread-II-solution-note.html) \n```\npublic int minMalwareSpread(int[][] graph, int[] initial) {\n    int minCount = graph.length+1, min = graph.length;\n    for(int node: initial) {\n        int[][] ngraph = copy(graph, node);\n        int count = calcCount(ngraph, initial, node);\n        if(count < minCount ||(count == minCount &&  node < min)) {\n            minCount = count;\n            min = node;\n        }\n    }\n    return min;\n}\n\npublic int calcCount(int[][] graph, int[] initial, int remove) {\n    Set<Integer> set = new HashSet<>();\n    Queue<Integer> queue = new LinkedList<>();\n    for(int node: initial) {\n        if(node != remove)  {\n            queue.add(node);\n        }\n    }\n    while(queue.size() > 0) {\n        int node = queue.poll();\n        set.add(node);\n        for(int i = 0; i < graph.length; ++i) {\n            if(graph[node][i] == 1 && !set.contains(i) ) {\n                queue.add(i);\n            }\n        }\n    }\n    return set.size();\n}\n\npublic int[][] copy(int[][] graph,  int remove) {\n    int[][] ngraph = new int[graph.length][graph.length];\n    for(int i = 0; i < graph.length; ++i) {\n        for(int j = 0;j < graph[i].length; ++j) {\n            if(i != remove && j != remove && graph[i][j] == 1) {\n                ngraph[i][j] = 1;\n            }\n        }\n    }\n    return ngraph;\n}\n```\n\n
[]