튜플을 이용해 union-find로 그룹핑했습니다 import sys input = sys.stdin.readline from collections import defaultdict def find(a): if parents[a] == a: return a parents[a] = find(parents[a]) return parents[a] def union(a, b): a = find(a) b = find(b) if a > b: a, b = b, a parents[b] = a N = int(input()) matrix = [list(map(int, list(input().rstrip()))) for _ in range(N)] delta = ((0, 1), (1, 0), (-1, 0), (0, -1)) ..