Skip to content

Commit 49ecd40

Browse files
committed
[23.01.26/Python] 미로탐색
1 parent bcfc8a2 commit 49ecd40

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

Python_BOJ_2023/2178_2.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 미로 탐색
2+
3+
from collections import deque
4+
5+
n, m = map(int, input().split())
6+
graph = [list(map(int, input())) for _ in range(n)]
7+
visited = [[0] * m for _ in range(n)]
8+
dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1]
9+
10+
def bfs(x, y):
11+
queue = deque()
12+
queue.append((x, y))
13+
visited[x][y] = 1
14+
15+
while queue:
16+
xx, yy = queue.popleft()
17+
for i in range(4):
18+
nx, ny = xx + dx[i], yy + dy[i]
19+
if 0 <= nx < n and 0 <= ny < m:
20+
if not visited[nx][ny]:
21+
if graph[nx][ny] == 1:
22+
visited[nx][ny] = visited[xx][yy] + 1
23+
queue.append((nx, ny))
24+
25+
bfs(0, 0)
26+
print(visited[n - 1][m - 1])

Python_BOJ_2023/이분탐색.py

-17
This file was deleted.

0 commit comments

Comments
 (0)