Skip to content

Commit

Permalink
solve : 2178 미로찾기
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed Apr 29, 2024
1 parent c89c3a0 commit 4381699
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions python/boj_2178.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from collections import deque

N, M = map(int, input().split())

graph = []

for _ in range(N):
graph.append(list(map(int, input())))


def BFS(x, y):
dx = [-1,1,0,0]
dy = [0,0,-1,1]

queue = deque()
queue.append((x,y))

while queue:
x, y = queue.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]

if nx < 0 or nx >= N or ny < 0 or ny >= M:
continue

if graph[nx][ny] == 0:
continue

if graph[nx][ny] == 1:
graph[nx][ny] = graph[x][y]+1
queue.append((nx, ny))

# 마지막 값에서 카운트 값 뽑기
return graph[N-1][M-1]


print(BFS(0, 0))

0 comments on commit 4381699

Please sign in to comment.