[알고리즘] DFS, BFS | 2667 단지번호 붙이기, 2606 바이러스
단지번호 붙이기 답: 더보기 BFS 풀이 from sys import stdin from collections import deque input = stdin.readline N = int(input()) graph = [] for _ in range(N): line = list(map(int, input().strip())) graph.append(line) # {위, 아래, 오른쪽, 왼쪽} 상하좌우 dx = [0, 0, 1, -1] #(0, 1) (0, -1) (1, 0) (-1, 0) dy = [1, -1, 0, 0] def bfs(graph, x, y): queue = deque() # 무엇으로 시작해야하나? x랑 y를 제공해주기 queue.append((x, y)) # 탐색 중 1인 부분은 0으..
2023. 10. 14.