content: package question0928_minimize_malware_spread_ii;
  
  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, initial[i]);
                  }
              }
              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, int removed) {
          visited[cur] = true;
          for (int i = 0; i < graph[cur].length; i++) {
              if (i == removed) {
                  continue;
              }
              if (graph[cur][i] == 1 && !visited[i]) {
                  dfs(graph, i, visited, removed);
              }
          }
      }
  
  }