Skip to content

Commit 8135236

Browse files
authored
[BOJ] 음식물피하기 (실버1)
1 parent 5a25306 commit 8135236

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

김지호/8주차/260216.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# https://www.acmicpc.net/problem/1743
2+
# 음식물 피하기, 실버1
3+
4+
import sys
5+
from collections import deque
6+
sys.stdin = open('../../../input.txt', 'r')
7+
8+
N, M, K = map(int, input().strip().split())
9+
board = [[0] * M for _ in range(N)]
10+
11+
for _ in range(K):
12+
row, col = map(int, input().strip().split())
13+
board[row - 1][col - 1] = 1
14+
15+
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
16+
17+
18+
def BFS(start_row, start_col):
19+
q = deque([(start_row, start_col)])
20+
board[start_row][start_col] = 0
21+
cnt = 1 # 시작점도 카운트
22+
23+
while q:
24+
cur_row, cur_col = q.popleft()
25+
26+
for dy, dx in directions:
27+
next_row, next_col = cur_row + dy, cur_col + dx
28+
29+
if 0 <= next_row < N and 0 <= next_col < M and board[next_row][next_col] == 1:
30+
board[next_row][next_col] = 0
31+
q.append((next_row, next_col))
32+
cnt += 1
33+
34+
return cnt
35+
36+
37+
answer = 1
38+
for row in range(N):
39+
for col in range(M):
40+
if board[row][col] == 1:
41+
answer = max(answer, BFS(row, col))
42+
43+
print(answer)

0 commit comments

Comments
 (0)