結果

問題 No.3580 二成分の和
コンテスト
ユーザー ゼット
提出日時 2026-07-03 21:48:06
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 954 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 144 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 69,888 KB
最終ジャッジ日時 2026-07-03 21:48:17
合計ジャッジ時間 6,338 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N,M,B=map(int,input().split())
result=[-1]*N
G=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
from collections import deque
for i in range(N):
    if result[i]!=-1:
        continue
    for x in range(B):
        S=deque()
        S.append(i)
        A=set()
        A.add(i)
        result[i]=x
        ans=True
        while S:
            pos=S.pop()
            for E in G[pos]:
                ne,t=E[:]
                if result[ne]==-1:
                    result[ne]=(t-result[pos])%B
                    S.append(ne)
                    A.add(ne)
                else:
                    if result[ne]!=(t-result[pos])%B:
                        ans=False
        if ans==True:
            break
        else:
            for pos in A:
                result[pos]=-1
if min(result)>=0:
    print('Yes')
    print(*result)
else:
    print('No')
                
0