[백준/Python] 2146번 - 다리 만들기
·
Algorithm/BaekJoon
import sys from collections import deque input = sys.stdin.readline n = int(input()) graph = [list(map(int, input().split())) for _ in range(n)] # 섬 찾기 def bfs(i, j): queue = deque([(i,j)]) visited[i][j] = True graph[i][j] = island while queue: x, y = queue.popleft() # lands.append((x,y)) for dx, dy in [(1, 0), (-1,0), (0,-1), (0,1)]: nx = x + dx ny = y + dy if 0 = n: continue # 다른 땅을 만나면 기존 답과 ..