Java | Simple DFS
\nclass Solution {\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        int n = graph.length, m = initial.length;\n        \n        List<I
```\nclass Solution {\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        int n = graph.length, m = initial.length;\n        \n        List<Integer>[] list = new ArrayList[n];\n        for(int i = 0; i < n; i++)\n            list[i] = new ArrayList<>();\n        \n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < n; j++){\n               if(graph[i][j] == 1 && i != j){\n                   list[i].add(j);\n                   list[j].add(i);\n               }\n            }\n        }\n        \n        Arrays.sort(initial);\n        int min = Integer.MAX_VALUE, ans = initial[0];\n        for(int i = 0; i < m; i++){\n            int[] arr = new int[1];\n            boolean[] visited = new boolean[n];\n            for(int j = 0; j < m; j++)\n                if(i != j)\n                    DFS(list, initial[j], initial[i], arr, visited);\n            \n            if(arr[0] < min){\n                min = arr[0];\n                ans = initial[i];\n            }\n        }\n        \n        return ans;\n    }\n    \n    public void DFS(List<Integer>[] list, int curr, int ignore, int[] arr, boolean[] visited){\n        if(curr == ignore || visited[curr])\n            return;\n        \n        arr[0]++;\n        visited[curr] = true;\n        \n        for(int i : list[curr])\n            if(!visited[i])\n                DFS(list, i, ignore, arr, visited);\n    }\n}\n```
[]