



- 최단거리 탐색 - BFS
- directions 변수 지정(상히좌우 이동)
- 현위치로부터 탐색할 사항
a. 상하좌우 이동 가능한가? (벽 확인🚪)
b. 이미 방문한 곳인가?
from collections import deque
def solution(maps):
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
n, m = len(maps), len(maps[0])
queue = deque([(0, 0)])
while queue:
x, y = queue.popleft()
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < n and 0 <= ny < m and maps[nx][ny] == 1:
maps[nx][ny] += maps[x][y]
queue.append((nx, ny))
return maps[n-1][m-1] if maps[n-1][m-1] > 1 else -1