問題一覧 > 通常問題

No.3425 Mod K Graph Increments (Easy)

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 63
作問者 : まみめ / テスター : harel hirayuu_yc syndrome kidodesu 👑 ArcAki 👑 qand rogi52 Eku
お気に入りにしたユーザー ProblemId : 12959 / 自分の提出
問題文最終更新日: 2026-01-12 12:56:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest YNUCPC Contest 2 (順位表) の他の問題:

※This problem is Mod K Graph Increments (Hard) with different constraints.

Problem Statement

You are given a tree graph $G$ with $N$ vertices and $M(=N-1)$ edges. For $i=1,2,...,M$, the $i$-th edge connects vertices $u_i$ and $v_i$.
There is a sequence $A = (A_1, …, A_N)$ of length $N$, all of whose elements are initially $0$.
Consider the following operation.

  • Choose $1$ edge from $G$, and let its endpoints be $x,y$. Replace $A_x$ with $(A_x + 1)$ $\rm{mod}$ $K$, and $A_y$ with $(A_y+1)$ $\rm{mod}$ $K$. Here, $a$ $\rm{mod} $ $b$ denotes the remainder when $a$ is divided by $b$.

Determine whether it is possible to make the sequence $A$ equal to the given sequence $B$ after performing the operation $0$ or more times.

You are given $T$ test cases; solve each of them.

Input

  • $1 \leq T \leq 2×10^5$
  • $1 \leq N \leq 2×10^5$
  • $M = N-1$
  • $1 \leq K \leq 10^9$
  • $1 \leq u_i,v_i \leq N$
  • $0 \leq B_i < K$
  • The given graph is a tree
  • All input values are integers
  • In $1$ input file, the sum of $N$ does not exceed $2×10^5$.

The input is given from standard input in the following format.

$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$ 
$\mathrm{case}_T$

Each case is given in the following format.

$N$ $M$ $K$  
$u_1$ $v_1$  
$u_2$ $v_2$  
$\vdots$  
$u_{M}$ $v_{M}$    
$B_1$ $B_2$ $ ... $ $B_N$

Output

Print $T$ lines.
On the $i$-th line, for the $i$-th test case, print Yes if $A$ can be made equal to $B$, and No otherwise.

Output

Print Yes if $A$ can be made equal to $B$, and No otherwise.
Print a newline at the end.

Sample

Sample 1
Input
2
3 2 3
1 2
2 3
2 0 1
2 1 2
1 2
1 0
Output
Yes
No

Consider test case number $1$.
In the initial state, $A=(0,0,0)$.
First, choosing edge $1$ and performing the operation gives $A=(1,1,0)$.
Next, choosing edge $1$ and performing the operation gives $A=(2,2,0)$.
Finally, choosing edge $2$ and performing the operation gives $A=(2,0,1)$, which matches $B=(2,0,1)$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。