結果

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

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def solve(N,M,K,UV,B):
    es = [[] for _ in range(N)]
    for u,v in UV:
        u,v = u-1,v-1
        es[u].append(v)
        es[v].append(u)
    
    A = [0] * N
    def rec(v,p=-1):
        for to in es[v]:
            if to==p: continue
            A[v] += rec(to,v)
            A[v] %= K
        ret = (B[v] - A[v]) % K
        return ret
    rec(0)
    return 'Yes' if A[0]==B[0] else 'No'


T = int(input())
for _ in range(T):
    N,M,K = map(int,input().split())
    UV = [tuple(map(int,input().split())) for _ in range(M)]
    B = list(map(int,input().split()))
    print(solve(N,M,K,UV,B))

0