good
Approach\n1. dfs -> \uBAA8\uB4E0 \uBC14\uC774\uB7EC\uC2A4 \uC9C0\uC5ED, \uADF8 \uC9C0\uC5ED\uC774 \uBBF8\uCE58\uB294 \uC704\uD611, \uACA9\uB9AC\uD558\uB294 \uB3
# Approach\n1. dfs -> \uBAA8\uB4E0 \uBC14\uC774\uB7EC\uC2A4 \uC9C0\uC5ED, \uADF8 \uC9C0\uC5ED\uC774 \uBBF8\uCE58\uB294 \uC704\uD611, \uACA9\uB9AC\uD558\uB294 \uB370 \uD544\uC694\uD55C \uBCBD\uC758 \uC218\n2. \uC704\uD611 \uAC00\uC7A5 \uD070 \uACF3 \uACA9\uB9AC = \uBCBD \uC138\uC6B0\uAE30 -> isInfected[i][j] = -1\n3. \uBC14\uC774\uB7EC\uC2A4 \uD655\uC0B0\n\n# Code\n```\nclass Solution {\n    int[] dx = {1, 0, -1, 0};\n    int[] dy = {0, 1, 0, -1};\n    int n, m;\n    public int containVirus(int[][] isInfected) {\n        // \uBC14\uC774\uB7EC\uC2A4 \uC9C0\uC5ED \uD655\uC778\n        // \uD655\uC0B0\uD55C\uB2E4\uBA74 \uD53C\uD574\uAC00 \uAC00\uC7A5 \uD070 \uACF3 \uCC3E\n        // \uBCBD \uC138\uC6B0\uAE30\n        // \uBC14\uC774\uB7EC\uC2A4 \uD655\uC0B0\n        n = isInfected.length;\n        m = isInfected[0].length;\n        int result = 0;\n        \n        while (true) {\n            List<Set<Integer>> regions = new ArrayList<>();\n            List<Set<Integer>> threats = new ArrayList<>();\n            List<Integer> walls = new ArrayList<>();\n            boolean[][] visited = new boolean[n][m];\n\n            for (int i = 0; i < n; i++) {\n                for (int j = 0; j < m; j++) {\n                    if (isInfected[i][j] == 1 && !visited[i][j]) {\n                        Set<Integer> region = new HashSet<>();\n                        Set<Integer> threat = new HashSet<>();\n                        int[] wall = new int[1];\n                        dfs(isInfected, visited, i, j, region, threat, wall);\n                        regions.add(region);\n                        threats.add(threat);\n                        walls.add(wall[0]);\n                    }\n                }\n            }\n\n            if (regions.isEmpty()) break;\n\n            int maxThreatIdx = 0;\n            for (int i = 0; i < threats.size(); i++) {\n                if (threats.get(i).size() > threats.get(maxThreatIdx).size()) {\n                    maxThreatIdx = i;\n                }\n            }\n\n            result += walls.get(maxThreatIdx);\n\n            for (int i = 0; i < regions.size(); i++) {\n                if (i == maxThreatIdx) {\n                    for (int num : regions.get(i)) {\n                        int y = num / m, x = num % m;\n                        isInfected[y][x] = -1;\n                    }\n                } else {\n                    for (int num : threats.get(i)) {\n                        int y = num / m, x = num % m;\n                        isInfected[y][x] = 1;\n                    }\n                }\n            }\n        }\n\n        return result;\n    }\n\n    private void dfs(int[][] isInfected, boolean[][] visited, int y, int x, Set<Integer> region, Set<Integer> threat, int[] wall) {\n        if (y < 0 || x < 0 || y >= n || x >= m || visited[y][x] || isInfected[y][x] != 1) return;\n\n        visited[y][x] = true;\n        region.add(y * m + x);\n\n        for (int d = 0; d < 4; d++) {\n            int ny = y + dy[d];\n            int nx = x + dx[d];\n            if (ny >= 0 && ny < n && nx >= 0 && nx < m) {\n                if (isInfected[ny][nx] == 0) {\n                    threat.add(ny * m + nx);\n                    wall[0]++;\n                } else if (isInfected[ny][nx] == 1 && !visited[ny][nx]) {\n                    dfs(isInfected, visited, ny, nx, region, threat, wall);\n                }\n            }\n        }\n    }\n}\n```
['Simulation', 'Java']