[백준/2178/파이썬] 미로탐색
소스코드 from collections import deque N, M = map(int, input().split()) graph = [] for _ in range(N): graph.append(list(map(int, input()))) def bfs(x, y): dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] queue = deque() queue.append((x, y)) while queue: x, y = queue.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx = N or ny = M: # 위치가 벗어나면 안됨 continue if graph[nx][ny] == 0: # 벽은 이동 X continue i..
[백준 7569/파이썬] 토마토
소스코드 import sys from collections import deque m,n,h = map(int,input().split()) graph = [] queue = deque([]) for i in range(h): tmp = [] for j in range(n): tmp.append(list(map(int,sys.stdin.readline().split()))) for k in range(m): if tmp[j][k]==1: queue.append([i,j,k]) graph.append(tmp) dx = [-1,1,0,0,0,0] dy = [0,0,1,-1,0,0] dz = [0,0,0,0,1,-1] while(queue): x,y,z = queue.popleft() for i in rang..