-
2178_미로탐색코테 대비 python/백준 2022. 10. 25. 23:55
https://www.acmicpc.net/problem/2178
from collections import deque n,m = map(int,input().split()) graph = [list(map(int,input())) for i in range(n)] visited = [[0]*m for i in range(n)] dx = [1,-1,0,0] dy=[0,0,1,-1] def bfs(x,y): q=deque([(x,y)]) visited[x][y] =1 while q: x,y = q.popleft() for j in range(4): nx = x+dx[j] ny = y+dy[j] if 0<=nx<n and 0<=ny<m and graph[nx][ny]==1: if visited[nx][ny] == 0 or visited[nx][ny] > visited[x][y]+1: q.append((nx,ny)) visited[nx][ny] = visited[x][y]+1 return bfs(0,0) print(visited[n-1][m-1])
'코테 대비 python > 백준' 카테고리의 다른 글
12919 A와 B2 (0) 2022.11.04 2667 단지번호 붙히기 (0) 2022.11.03 2606 바이러스 (0) 2022.09.28 8979 올림픽 (2) 2022.09.16 5635 생일 (0) 2022.09.08