#P11448. 「ALFR Round 3」D 核裂变

    ID: 10454 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创O2优化广度优先搜索 BFS洛谷月赛

「ALFR Round 3」D 核裂变

Description

There are nn radioactive atoms that will undergo fission reactions for kk seconds. If at the beginning of the tt-th second, atom ii is bombarded by b (b>0)b\ (b>0) neutrons, it will release ai+ba_i + b units of energy during the tt-th second and will release 11 neutron to each of the atoms numbered xi,1,xi,2,,xi,aix_{i,1}, x_{i,2}, \ldots, x_{i,a_i}. Thus, at the beginning of the next second (t+1t+1), the number of neutrons hitting each of xi,1,xi,2,,xi,aix_{i,1}, x_{i,2}, \dots, x_{i,a_i} will increase by 11 (if t=kt=k, meaning this is the last second, then neutrons will not be released by bombarded atoms). If an atom is not bombarded by any neutrons at the beginning of a second, it will not release energy or neutrons.

At the beginning of each second, atoms numbered v1,v2,,vmv_1, v_2, \ldots, v_m are bombarded by 11 neutron. Therefore, from the beginning of the first second until the end of the kk-th second, how much energy will each atom release?

Output the answer modulo 998244353998244353.

Input Format

The first line contains three integers n,k,mn, k, m, representing the number of atoms, the duration of the reaction, and the number of atoms hit each second.

The second line contains mm integers v1,v2,,vmv_1, v_2, \dots, v_m.

The next nn lines contain the information for each atom, formatted as follows:

The ii-th line contains ai+1a_i + 1 integers, where the first number is aia_i, followed by aia_i integers xi,1,xi,2,,xi,aix_{i,1}, x_{i,2}, \dots, x_{i,a_i}.

Output Format

Output one line containing nn integers. The ii-th number is the total energy released by atom ii from the start of the 11-st second to the termination moment of the kk-th second, with the result taken modulo 998244353998244353.

3 3 1
1
1 2
1 3
1 1
6 4 2

3 1000000000000000000 1
1
1 2
1 3
1 1
151723985 433897441 433897439

Hint

Explanation of sample #1:

  • In the first second, atom 11 is hit by 11 neutron, releasing 11 neutron to atom 22, thus releasing 22 units of energy.
  • In the second second, atom 11 is hit by 11 neutron, releasing 11 neutron to atom 22, and releasing 22 units of energy. Simultaneously, atom 22 is hit by 11 neutron, releasing 11 neutron to atom 33, and releasing 22 units of energy.
  • In the third second, atom 11 is hit by 11 neutron, releasing 22 units of energy. Meanwhile, atom 22 is hit by 11 neutron, releasing 22 units of energy, and atom 33 is hit by 11 neutron, releasing 22 units of energy.

Thus, atom 11 releases a total of 66 units of energy, atom 22 releases 44 units of energy, and atom 33 releases 22 units of energy.

Subtask Score Constraints
00 55 m=n,vi=i,ai=1,xi,1=1m=n,v_i=i,a_i=1,x_{i,1}=1
11 1010 m=1,v1=1,ai=1,xi,1=(imodn)+1m=1,v_1=1,a_i=1,x_{i,1}=(i \bmod n)+1
22 2020 n,ai103n,\sum a_i \leq 10^3, 1k1061 \leq k \leq 10^6
33 3030 1k1061 \leq k \leq 10^6
44 3535 -

For all the tests, 1n,ai5×1051\le n,\sum a_i\le5\times10^5, 1k10181 \leq k \leq 10^{18}, 0ai5×1050 \leq a_i \leq 5 \times 10^5, 1m,vi,xi,jn1\le m,v_i,x_{i,j}\le n, and v1,v2,,vmv_1,v_2,\dots,v_m are distinct, while xi,1,xi,2,,xi,aix_{i,1},x_{i,2},\dots,x_{i,a_i} are also distinct.

This problem has a large input, please use faster I/O methods.