boj2178-미로탐색
문제 : 미로탐색
import sys
from collections import deque
if __name__ == "__main__":
input = sys.stdin.readline
row, col = map(int, input().split())
graph = []
for i in range(row):
graph.append(list(map(int, input().rstrip())))
# print(graph)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
q = deque()
q.append([0,0])
while q:
x , y = q.popleft()
for i in range(4):
tx = x + dx[i]
ty = y + dy[i]
if 0 <= tx < row and 0 <= ty < col and graph[tx][ty] == 1:
q.append([tx, ty])
graph[tx][ty] = graph[x][y] + 1
# print('result: ' , graph)
print(graph[row-1][col-1])
0,0 부터 시작해서 상하좌우를 탐색하는 bfs
q에 넣을 때마다 해당 좌표의 값 +1
Author And Source
이 문제에 관하여(boj2178-미로탐색), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dust_potato/boj2178-미로탐색저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)