์ฝ๋
const fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const [Y, X, K] = input.shift().split(" ").map(Number);
const arr = Array.from(new Array(Y), () => new Array(X).fill(0));
for (let i = 0; i < K; i++) {
const [y, x] = input[i].split(" ").map(Number);
arr[y-1][x-1] = 1;
}
const dir = [
[0, 1],
[0, -1],
[1, 0],
[-1, 0],
];
const DFS = (i, j) => {
const queue = [[i, j]];
let size = 0;
arr[i][j] = -1;
while (queue.length) {
const [pY, pX] = queue.pop();
size++;
for (let i = 0; i < 4; i++) {
const nX = pX + dir[i][1];
const nY = pY + dir[i][0];
if (nX >= 0 && nX < X && nY >= 0 && nY < Y && arr[nY][nX] === 1) {
queue.push([nY, nX]);
arr[nY][nX] = -1;
}
}
}
return size;
};
const result = [];
for (let i = 0; i < Y; i++) {
for (let j = 0; j < X; j++) {
if (arr[i][j] === 1) {
result.push(DFS(i, j));
}
}
}
console.log(Math.max(...result));
์ฝ๋๋ฅผ ์ ์ฝ์์ต๋๋ค. DFS๋ฅผ ์ด์ฉํด ๋ฌธ์ ๋ฅผ ํจ์จ์ ์ผ๋ก ํด๊ฒฐํ์ ๊ฒ์ด ์ธ์๊น์์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.