#P10315. [SHUPC 2024] 原神,启动!
[SHUPC 2024] 原神,启动!
Problem Description
Electro elemental totems have the following properties:
- Each totem has states, one of .
- When a totem is attacked once, it moves to the next state (the next state of is ).
- 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 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 Electro elemental totems, and each totem has states. For each totem , when it is attacked, there are other totems that will move to the next state together with it.
Given the initial state and the target state of the Electro elemental totems, compute how many times you need to attack each totem in order to transform the totems from state to .
If there is no solution, output niuza.
Input Format
The first line contains two positive integers . It is guaranteed that is prime.
In the next lines, line contains the following data:
- First read an integer , which indicates how many totems will be triggered when attacking this totem.
- Then read integers; the -th integer is and , indicating the index of a totem triggered by totem .
Then there are two more lines:
The first line contains integers; the -th integer is , representing the initial state of the -th Electro elemental totem, where .
The second line contains integers; the -th integer is , representing the target state of the -th Electro elemental totem, where .
Output Format
If there is a solution, output integers each less than , 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