結果
| 問題 | No.3552 Triangular Coloring |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-05-28 02:56:19 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 847 ms / 2,000 ms |
| コード長 | 723 bytes |
| 記録 | |
| コンパイル時間 | 126 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 179,048 KB |
| 最終ジャッジ日時 | 2026-05-28 02:56:29 |
| 合計ジャッジ時間 | 8,947 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 17 |
ソースコード
import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
E=[set() for i in range(N)]
for i in range(M):
x,y=list(map(int,input().split()))
x-=1
y-=1
E[x].add(y)
E[y].add(x)
ANS=[0]*N
ANS2=[[0]*5 for i in range(N)]
ANS[0]=1
x=list(E[0])[0]
ANS[x]=2
for to in E[0]:
if to in E[0] and to in E[x]:
y=to
break
ANS[y]=3
Q=[0,x,y]
while Q:
x=Q.pop()
for to in E[x]:
if ANS[to]==1:
continue
ANS2[to][ANS[x]]=1
if ANS[to]==0 and sum(ANS2[to])==3:
for i in range(1,5):
if ANS2[to][i]==0:
color=i
ANS[to]=color
Q.append(to)
print("Yes")
print(*ANS)
titia