AtCoder Grand Contest 063
翻译中…
Problem Statement
翻译中…
There is a rooted tree with $N$ vertices numbered $1$ to $N$. Vertex $1$ is the root, and the parent of vertex $i$ ($2\leq i\leq N$) is $P_i$.
翻译中…
You are given a non-negative integer $r$ and a sequence of non-negative integers $A = (A_1, \ldots, A_N)$. You can perform the following operation on the sequence any number of times, possibly zero.
翻译中…
- Choose an
$i$such that$i\geq 2$and$A_i \geq 1$. Replace$A_i$with$A_i - 1$and$A_{P_i}$with$A_{P_i}+r$.
翻译中…
Find the number, modulo $998244353$, of possible final states of the sequence $A$.
翻译中…
Constraints
翻译中…
$2\leq N\leq 300$$1\leq P_i \leq i - 1$($2\leq i\leq N$)$0\leq r \leq 10^9$$0\leq A_i \leq 10^9$
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
P_2 \ldots P_N
r
A_1 \ldots A_N
翻译中…
Output
翻译中…
Print the number, modulo $998244353$, of possible final states of the sequence $A$.
翻译中…
样例
Input #1
3
1 1
2
1 1 1
Output #1
4
The four possible final states of $A$ are $(1,1,1)$, $(3,0,1)$, $(3,1,0)$, and $(5,0,0)$.
Input #2
3
1 2
1
1 1 1
Output #2
5
The five possible final states of $A$ are $(1,1,1)$, $(1,2,0)$, $(2,0,1)$, $(2,1,0)$, and $(3,0,0)$.
Input #3
3
1 2
2
1 1 1
Output #3
6
The six possible final states of $A$ are $(1,1,1)$, $(1,3,0)$, $(3,0,1)$, $(3,2,0)$, $(5,1,0)$, and $(7,0,0)$.
Input #4
5
1 1 3 3
2
0 1 0 1 2
Output #4
48
Input #5
5
1 1 3 3
123456789
1 2 3 4 5
Output #5
87782255
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。