Problem Statement
You are given a rooted tree with $N$ vertices. The vertices are numbered $1$ to $N$, and the root is vertex $1$. The parent of each vertex $i$ except the root is vertex $P_i$. Each vertex, including the root, has ** no child or exactly two children**.
Determine whether it is possible to write one of the characters X and Y on each vertex of the given tree to satisfy the following condition.
Condition: For each edge of the tree, consider the string of length $2$ obtained by concatenating the characters written on the endpoints in the order from the parent $P_i$ to the child $i$. Among the $(N - 1)$ strings obtained in this way,
- exactly
$A$areXX, - exactly
$B$areXY, - exactly
$C$areYX, and - none is
YY.
You have $T$ test cases to solve.
Constraints
$T \geq 1$$N \geq 1$- For each input, the sum of
$N$over the test cases is at most$10^4$. $A \geq 0$$B \geq 0$$C \geq 0$$A + B + C = N - 1$$1 \leq P_i < i \ \ (2 \leq i \leq N)$- Each vertex
$k \ (1 \leq k \leq N)$occurs as a parent$P_i \ (2 \leq i \leq N)$zero times or twice in total.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Each test case $\mathrm{case}_i \ (1 \leq i \leq T)$ is in the following format:
N A B C
P_2 P_3 \cdots P_N
Output
Print $T$ lines. The $i$-th line should contain Yes if there is a way to write characters to satisfy the condition, and No otherwise.
样例
3
7 2 2 2
1 1 2 2 3 3
7 0 2 4
1 1 2 2 3 3
7 2 0 4
1 1 2 2 4 4
Yes
Yes
No
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。