IT보안관의 공부 클라우드
[이코테 BFS]미로 탈출 본문
https://www.youtube.com/watch?v=7C9RgOcvkvo&list=PLRx0vPvlEmdAghTr5mXQxGpHjWqSz0dgC&index=3
from collections import deque
def bfs(x,y,graph):
q = deque([[x,y,graph[x][y]]])
print(q)
prev=0
while 1:
a,b,c=q.popleft()
# print(q, a, b)
if a == n - 1 and b == m - 1:
graph[a][b] +=c
return graph
if a < 0 or b < 0 or a >= n or b>= m: continue
print(q, a, b)
for i in graph:
print(i)
if graph[a][b] == 0:
continue
elif graph[a][b] > 1:
continue
else:
graph[a][b] += c
q.append([a + 1,b,graph[a][b]])
q.append([a -1, b,graph[a][b]])
q.append([a, b+1,graph[a][b]])
q.append([a, b-1,graph[a][b]])
n,m = map(int,input().split())
graph=[]
cnt = 0
for i in range(n):
graph.append(list(map(int,input())))
bfs(0,0,graph)
for i in graph:
print(i)
print(n,m)
print(graph[n-1][m-1]-1)
'코딩 테스트 > 기타' 카테고리의 다른 글
[이코테 DFS]음료수 얼려먹기 (0) | 2022.07.03 |
---|
Comments