题目描述
Problem Description
Thunder elemental steles have the following properties:
- They have $m$ states, one of $0, 1, \cdots, m-1$.
- When a stele is attacked, it transitions to the next state (with $m-1$ transitioning to $0$).
- When a stele is attacked, it also causes some other steles to transition to the next state.
When all $n$ steles are in the same state, the puzzle is solved. However, Xiao A finds the stele puzzle in the game too simple, as using Keqing's "Slay the Ox" to randomly attack all the elemental steles once can solve the puzzle. Therefore, he starts thinking about a more complex version.
Now there are $n$ thunder elemental steles, each with $m$ states. For each stele $i$, when it is attacked, $k_i$ other steles transition to the next state along with it.
Given the initial state $s$ and the target state $t$ of $n$ thunder elemental steles, calculate how many times each stele needs to be attacked to transition from state $s$ to state $t$.
If there is no solution, output niuza.
Input Format
The first line contains two positive integers $n, m\ (1 \le n \le 100, m \le 10^9)$, guaranteed that $m$ is a prime number.
The next $n$ lines, for the $i$-th line, will read the following data:
- First, a number $k\ (0 \le k < n)$, indicating the number of steles that will transition when this stele is attacked.
- Next, $k$ numbers, the $j$-th number $a_j\ (1 \le a_j \le n, a_j \neq i$ and $a_{j-1} < a_j)$ indicating the stele number that $i$ transitions.
The next two lines:
- The first line contains $n$ numbers, the $i$-th number $s_i$ indicating the initial state of the $i$-th thunder elemental stele $s_i\ (0 \le s_i < m)$.
- The second line contains $n$ numbers, the $i$-th number $t_i$ indicating the target state of the $i$-th thunder elemental stele $t_i\ (0 \le t_i < m)$.
Output Format
If there is a solution, output $n$ numbers less than $m$, indicating how many times each stele should be attacked, separated by spaces. For multiple solutions, output any one of them.
If there is no solution, output niuza.
Sample Input and Output
Sample Input #1
3 3
1 3
2 1 3
1 2
0 0 0
0 2 1
Sample Output #1
2 1 1
Sample Input #2
3 3
2 2 3
2 1 3
1 1
0 0 0
0 1 2
Sample Output #2
niuza
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分