백준 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.