각 조합마다 bfs 돌려서 최소값을 비교해줍니다. import sys input = sys.stdin.readline from collections import deque from itertools import combinations def bfs(q): visited = [[False] * N for _ in range(N)] for x, y in q: visited[x][y] = True time = -1 cnt = len(q) while q: for _ in range(len(q)): x, y = q.popleft() for i in range(4): nx, ny = x + dx[i], y + dy[i] if 0