๋ฐฑ์ค 7576๋ฒ ํ ๋งํ (BFS ๋ฌธ์ ) _ ํ์ด์ฌ
from collections import deque# ์
๋ ฅ ๋ฐ๊ธฐM, N = map(int, input().split())tomato = [list(map(int, input().split())) for _ in range(N)]# 4๋ฐฉํฅ(์, ํ, ์ข, ์ฐ) ์ ์dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]# ์ต์ ํ ๋งํ ์ ์์น ํ์ ๋ฃ๊ธฐqueue = deque()# ์ด๊ธฐ ์ต์ ํ ๋งํ ์์น ์ฐพ๊ธฐfor i in range(N): for j in range(M): if tomato[i][j] == 1: # ์ต์ ํ ๋งํ ์ผ ๊ฒฝ์ฐ queue.append((i, j))# BFS ์์def bfs(): # ํ๊ฐ ๋น ๋๊น์ง ๋ฐ๋ณต while queu..
2025. 2. 18.