# フォーマットチェック import re import sys content = input() pattern = r'^(\d+)$' result = re.match(pattern, content) if not result: sys.exit("format error.") Q = int(content) if not (1 <= Q and Q <= 2024): sys.exit("Q") for _ in range(Q): content = input() pattern = r'^(\d+)$' result = re.match(pattern, content) if not result: sys.exit("format error.") N = int(content) if not (1 <= N): sys.exit("N") ws = [] for __ in range(N - 1): content = input() pattern = r'^(\d+) (\d+) (\d+)$' result = re.match(pattern, content) if not result: sys.exit("format error.") u, v, w = map(int, content.split()) if not (1 <= u and u < v and v <= N): sys.exit("u, v") ws.append(w) # 木であるかはチェックしていない content = input() pattern = r'^(\d+) (\d+)$' result = re.match(pattern, content) if not result: sys.exit("format error.") H, W = map(int, content.split()) if not (1 <= H and H <= 12): sys.exit("H") if not (1 <= W and W <= 25): sys.exit("W") if not (N <= H * W): sys.exit("N") for i in range(N - 1): if not (ws[i] <= H * W): sys.exit("w") for __ in range(H): content = input() pattern = r'^(.|#){' + str(W) + '}$' result = re.match(pattern, content) if not result: sys.exit("format error.") # 塗り方が木的であるかはチェックしていない print("OK")