visited 뒤에 [nx][ny]안붙힌거 찾느라 1시간 걸렸다. import sys input = sys.stdin.readline from collections import deque def BFS(x,y,h): global result queue = deque() queue.append([x,y]) dx = [0,0,1,-1] dy = [1,-1,0,0] out_rain = False cnt = 1 visited[x][y] = True while queue: x,y = queue.popleft() for i in range(4): nx = x+dx[i] ny = y+dy[i] if 0