結果
| 問題 | No.3552 Triangular Coloring |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-22 23:26:17 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,294 bytes |
| 記録 | |
| コンパイル時間 | 263 ms |
| コンパイル使用メモリ | 85,504 KB |
| 実行使用メモリ | 261,272 KB |
| 最終ジャッジ日時 | 2026-05-22 23:26:38 |
| 合計ジャッジ時間 | 16,878 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 RE * 15 |
ソースコード
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 8)
N, M = map(int, input().split())
G = [set() for _ in range(N)]
edges = []
for _ in range(M):
u, v = map(int, input().split())
u -= 1
v -= 1
edges.append((u, v))
G[u].add(v)
G[v].add(u)
def check(i):
if len(G[i]) != 3:
return False
x, y, z = G[i]
return x in G[y] and y in G[z] and z in G[x]
used = [False] * N
ok = set(filter(check, range(N)))
child = defaultdict(list)
while ok:
i = ok.pop()
used[i] = True
idx = sorted(G[i])
for x in idx:
if check(x):
ok.remove(x)
for x in idx:
G[x].remove(i)
if check(x):
ok.add(x)
G[i].clear()
k = tuple(idx)
child[k].append(i)
cur = tuple(sorted(filter(lambda i: not used[i], range(N))))
assert len(cur) == 3
color = [-1] * N
color[cur[0]] = 1
color[cur[1]] = 2
color[cur[2]] = 3
def dfs(cur):
x, y, z = cur
c = 10 - sum(color[k] for k in cur)
for i in child[cur]:
color[i] = c
dfs(tuple(sorted((x, y, i))))
dfs(tuple(sorted((y, z, i))))
dfs(tuple(sorted((z, y, i))))
dfs(cur)
assert all(1 <= c <= 4 for c in color)
assert all(color[u] != color[v] for u, v in edges)
print("Yes")
print(*color)