File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 33# N, M을 공백을 기준으로 구분하여 입력 받기
44n , m = map (int , input ().split ())
55# 2차원 리스트의 맵 정보 입력 받기
6- array = []
6+ graph = []
77for i in range (n ):
8- array .append (list (map (int , input ())))
8+ graph .append (list (map (int , input ())))
99
1010# 이동할 네 가지 방향 정의 (상, 하, 좌, 우)
1111dx = [- 1 , 1 , 0 , 0 ]
@@ -24,17 +24,17 @@ def bfs(x, y):
2424 nx = x + dx [i ]
2525 ny = y + dy [i ]
2626 # 미로 찾기 공간을 벗어난 경우 무시
27- if nx < 0 or ny < 0 or nx >= n or ny >= m :
27+ if nx < 0 or nx >= n or ny < 0 or ny >= m :
2828 continue
2929 # 벽인 경우 무시
30- if array [nx ][ny ] == 0 :
30+ if graph [nx ][ny ] == 0 :
3131 continue
3232 # 해당 노드를 처음 방문하는 경우에만 최단 거리 기록
33- if array [nx ][ny ] == 1 :
34- array [nx ][ny ] = array [x ][y ] + 1
33+ if graph [nx ][ny ] == 1 :
34+ graph [nx ][ny ] = graph [x ][y ] + 1
3535 queue .append ((nx , ny ))
3636 # 가장 오른쪽 아래까지의 최단 거리 반환
37- return array [n - 1 ][m - 1 ]
37+ return graph [n - 1 ][m - 1 ]
3838
3939# BFS를 수행한 결과 출력
4040print (bfs (0 , 0 ))
You can’t perform that action at this time.
0 commit comments