#P10315. [SHUPC 2024] 原神,启动!

    ID: 11729 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2024Special Judge高斯消元高校校赛

[SHUPC 2024] 原神,启动!

Problem Description

Electro elemental totems have the following properties:

  1. Each totem has mm states, one of 0,1,,m10,1,\cdots,m-1.
  2. When a totem is attacked once, it moves to the next state (the next state of m1m-1 is 00).
  3. When a certain totem is attacked once, it will also cause some other totems to move to the next state together.

When the states of all nn totems are the same, the puzzle is solved. However, player A thinks the totem puzzles in the game are too easy: he can solve them by using Keqing’s “Zhan Jin Niu Za” to attack all the totems randomly once, so he starts thinking about a more complex version.

Now there are nn Electro elemental totems, and each totem has mm states. For each totem ii, when it is attacked, there are kik_i other totems that will move to the next state together with it.

Given the initial state ss and the target state tt of the nn Electro elemental totems, compute how many times you need to attack each totem in order to transform the totems from state ss to tt.

If there is no solution, output niuza.

Input Format

The first line contains two positive integers n,m (1n100,m109)n,m\ (1\le n\le100,m\le10^9). It is guaranteed that mm is prime.

In the next nn lines, line ii contains the following data:

  • First read an integer k (0k<n)k\ (0\le k<n), which indicates how many totems will be triggered when attacking this totem.
  • Then read kk integers; the jj-th integer is aj (1ajn,ajia_j\ (1\le a_j \le n, a_j\neq i and aj1<aj)a_{j-1}<a_j), indicating the index of a totem triggered by totem ii.

Then there are two more lines:

The first line contains nn integers; the ii-th integer is sis_i, representing the initial state of the ii-th Electro elemental totem, where si (0si<m)s_i\ (0\le s_i <m).

The second line contains nn integers; the ii-th integer is tit_i, representing the target state of the ii-th Electro elemental totem, where ti (0ti<m)t_i\ (0\le t_i <m).

Output Format

If there is a solution, output nn integers each less than mm, representing how many times you should attack each totem. Separate them with spaces. If there are multiple solutions, output any one of them.

If there is no solution, output niuza.

3 3
1 3
2 1 3
1 2
0 0 0
0 2 1
2 1 1
3 3
2 2 3
2 1 3
1 1
0 0 0
0 1 2
niuza

Hint

Translated by ChatGPT 5