結果

問題 No.3425 Mod K Graph Increments (Easy)
コンテスト
ユーザー るるまるふぁんくらぶ
提出日時 2026-01-11 14:22:38
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 801 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 404 ms
コンパイル使用メモリ 82,776 KB
実行使用メモリ 80,568 KB
最終ジャッジ日時 2026-01-11 14:22:42
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

import pypyjit

sys.setrecursionlimit(2 * 10**5 + 1)
pypyjit.set_param("max_unroll_recursion=-1")


def solve():
    N, M, K = [int(s) for s in input().split()]
    tree = [[] for _ in range(N)]

    for _ in range(M):
        u, v = [int(s) - 1 for s in input().split()]
        tree[u].append(v)
        tree[v].append(u)

    B = [int(s) for s in input().split()]

    def dp(curr, prev):
        # 子の寄与
        children = 0

        for to in tree[curr]:
            if to == prev:
                continue

            children -= dp(to, curr)
            children %= K

        return (children + B[curr]) % K

    if dp(0, -1) == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    T = int(input())

    for _ in range(T):
        solve()
0