Java DFS
\nclass Solution {\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        \n        if (initial.length == 1) return initial[0];\n        \n  
```\nclass Solution {\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        \n        if (initial.length == 1) return initial[0];\n        \n        int min_val = Integer.MAX_VALUE;\n        int min_idx = 0;\n        \n        for (int i = 0; i < initial.length; ++i)\n        {\n            Set<Integer> infected = new HashSet();\n            for (int j = 0; j < initial.length; ++j)\n            {\n                if (i != j)\n                {\n                    dfs(graph, infected, initial[j], initial[i]);\n                }\n            }\n            \n            if (infected.size() < min_val)\n            {\n                min_val = infected.size();\n                min_idx = initial[i];\n            }\n            else if (infected.size() == min_val)\n            {\n                min_idx = Math.min(initial[i], min_idx);\n            }\n        }\n        \n        return min_idx;\n    }\n    \n    void dfs(int[][] graph, Set<Integer> infected, int curr, int removed)\n    {\n        if (!infected.contains(curr) && curr != removed)\n        {\n            infected.add(curr);\n            for (int j = 0; j < graph[curr].length; ++j)\n            {\n                if (graph[curr][j] == 1)\n                {\n                    dfs(graph, infected, j, removed);\n                }\n            }\n        }\n    }\n}\n```
[]