8000 Directory Structure fix · jason9288/Algorithm_Study@ee41d7c · GitHub
[go: up one dir, main page]

< 8000 a href="#start-of-content" data-skip-target-assigned="false" class="px-2 py-4 color-bg-accent-emphasis color-fg-on-emphasis show-on-focus js-skip-to-content">Skip to content

Commit ee41d7c

Browse files
committed
Directory Structure fix
1 parent 6163f1a commit ee41d7c

File tree

7 files changed

+32
-0
lines changed

7 files changed

+32
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
문제: 미로탐색 (http://boj.kr/2178)
3+
Tier: Silver 1 (2021.01.18 기준)
4+
Comment: 최단거리 -> BFS!
5+
"""
6+
7+
from collections import deque
8+
import sys
9+
10+
N, M = map(int, sys.stdin.readline().rstrip().split())
11+
graph = [list(input()) for i in range(N)]
12+
visited = [[0 for i in range(M)] for i in range(N)]
13+
dx = [1, -1, 0, 0]
14+
dy = [0, 0, 1, -1]
15+
16+
def bfs():
17+
dq = deque()
18+
dq.append((0, 0))
19+
visited[0][0] = 1
20+
21+
while len(dq):
22+
x, y = dq.popleft()
23+
for i in range(4):
24+
X = x + dx[i]; Y = y + dy[i];
25+
if X < 0 or X == N or Y < 0 or Y == M:
26+
continue
27+
if graph[X][Y] == '1' and visited[X][Y] == 0:
28+
visited[X][Y] = visited[x][y] + 1
29+
dq.append((X, Y))
30+
31+
bfs()
32+
print(visited[N - 1][M - 1])

0 commit comments

Comments
 (0)
0