結果

問題 No.3552 Triangular Coloring
コンテスト
ユーザー titia
提出日時 2026-05-28 02:56:19
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 847 ms / 2,000 ms
コード長 723 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 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
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0