#P11448. Radioactive Atom Fission Reaction

    ID: 13528 Type: Default 1000ms 256MiB

Radioactive Atom Fission Reaction

Radioactive Atom Fission Reaction

You are given $n$ radioactive atoms undergoing a fission reaction that lasts for $k$ seconds. Each atom $i$ is associated with an integer $a_i$, and when atom $i$ is hit by neutrons at the beginning of a second, it may release energy and trigger further reactions.

More precisely, at the beginning of a second $t$, if atom $i$ is bombarded with $b$ neutrons (with $b>0$), then during the $t$-th second it releases a total energy of $$a_i + b$$ (in arbitrary units) and, if $t \lt k$, it releases exactly one neutron to each of the atoms numbered $$x_{i,1}, x_{i,2}, \dots, x_{i,a_i}.$$ These released neutrons will add one additional neutron to the count of the corresponding atoms at the beginning of second $t+1$. Note that if an atom is not hit by any neutron at the beginning of a second, it will neither release energy nor produce any neutrons. Also, if $t=k$ (i.e. the last second), even if an atom is bombarded, it will not release any neutrons for further reactions.

In addition, at the beginning of every second, the atoms with indices $v_1, v_2, \dots, v_m$ are externally bombarded with one neutron each. Your task is to calculate the total energy released by each atom from the start of the reaction (second 1) until the end of the $k$-th second. Since the answers can be very large, output the answer for each atom modulo $$998244353$$.

inputFormat

The input is given as follows:

$n$ $k$ $m$
$a_1$ $a_2$ ... $a_n$
[list for atom 1: $x_{1,1}$ $x_{1,2}$ ... $x_{1,a_1}$]
[list for atom 2: $x_{2,1}$ $x_{2,2}$ ... $x_{2,a_2}$]
...
[list for atom $n$: $x_{n,1}$ $x_{n,2}$ ... $x_{n,a_n}$]
$v_1$ $v_2$ ... $v_m$

Note: If $a_i=0$, the corresponding list of targets will be empty (or a blank line).

outputFormat

Output one line containing $n$ integers, where the $i$-th integer represents the total energy released by atom $i$ modulo $$998244353$$.

sample

3 2 1
1 0 1
2

1
1
4 1 0