python - BFS - problem solving example
강의: https://youtu.be/7C9RgOcvkvo 코드: # BFS example from collections import deque # 1. input n, m = map(int, input.split()) graph=[] for i in range(n): graph[i].append(list(map(int, input()))) # 2. find shortest path # top, bottom, left, right dr = [-1, 1, 0, 0] dc = [0, 0, -1, 1] def bfs(r,c): queue = deque() queue.append(r,c) while queue: r,c = queue.popleft() for d in range(4): nr = r + dr[d] ..
2022. 3. 5.