[백준/2667/파이썬] 단지번호붙이기
소스코드 from collections import deque N = int(input()) graph = [] for i in range(N): graph.append(list(map(int, input()))) def bfs(graph,x,y): dx = [-1,1,0,0] dy = [0,0,-1,1] queue = deque() queue.append((x,y)) graph[x][y] = 0 cnt = 1 while (queue) : x,y = queue.popleft() for i in range (4): ax = x + dx[i] ay = y + dy[i] if (ax = N) or (ay =N): continue if graph[ax][ay] == 1: graph[ax][ay] = 0 queu..
[백준/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..