content: package question0924_minimize_malware_spread;
  
  import java.util.Arrays;
  
  public class Solution {
  
    public int minMalwareSpread(int[][] graph, int[] initial) {
      Arrays.sort(initial);
      int result = -1;
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < initial.length; i++) {
        // 删除节点 initial[i]
        boolean[] visited = new boolean[graph.length];
        for (int j = 0; j < initial.length; j++) {
          if (j == i) {
            continue;
          }
          if (!visited[initial[j]]) {
            dfs(graph, initial[j], visited);
          }
        }
        int temp = 0;
        for (int j = 0; j < visited.length; j++) {
          if (visited[j]) {
            temp++;
          }
        }
        if (temp < min) {
          min = temp;
          result = initial[i];
        }
      }
      return result;
    }
  
    private void dfs(int[][] graph, int cur, boolean[] visited) {
      visited[cur] = true;
      for (int i = 0; i < graph[cur].length; i++) {
        if (graph[cur][i] == 1 && !visited[i]) {
          dfs(graph, i, visited);
        }
      }
    }
  
  }