結果

問題 No.3425 Mod K Graph Increments (Easy)
コンテスト
ユーザー titia
提出日時 2026-01-17 01:10:30
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,000 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 276 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 78,424 KB
最終ジャッジ日時 2026-01-17 01:10:32
合計ジャッジ時間 2,614 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

T=int(input())

for tests in range(T):
    N,M,K=map(int,input().split())

    E=[[] for i in range(N)]

    for i in range(M):
        x,y=map(int,input().split())
        x-=1
        y-=1
        E[x].append(y)
        E[y].append(x)
    B=list(map(int,input().split()))

    
    # 木のHL分解+LCA

    ROOT=0

    QUE=[ROOT] 
    Parent=[-1]*N
    Parent[ROOT]=N # ROOTの親を定めておく.
    Child=[[] for i in range(N)]
    TOP_SORT=[] # トポロジカルソート

    while QUE: # トポロジカルソートと同時に親を見つける
        x=QUE.pop()
        TOP_SORT.append(x)
        for to in E[x]:
            if Parent[to]==-1:
                Parent[to]=x
                Child[x].append(to)
                QUE.append(to)

    for x in TOP_SORT[::-1]:
        if x==0:
            break
        if B[x]!=0:
            B[Parent[x]]-=B[x]
            B[x]=0

    if B[0]%K==0:
        print("Yes")
    else:
        print("No")
0