#P2435. 染色
染色
Description
There is an -row, -column grid graph. You need to color each point with one of colors so that no two adjacent points have the same color. Given the colorings of the first row and the last row, find the total number of valid colorings.
The answer is taken modulo .
Input Format
The first line contains three integers .
The second line contains integers, the coloring of the first row, where each color is represented by .
The third line contains integers, the coloring of the last row, where each color is represented by .
Output Format
Output a single integer, the answer.
The answer is taken modulo .
3 2 3
1 0
1 0
3
Hint
Sample Explanation
Scheme 1
1 0
0 1
1 0
Scheme 2
1 0
0 2
1 0
Scheme 3
1 0
2 1
1 0
Constraints
| Test point ID | |||
|---|---|---|---|
For of the testdata, .
Please note that the values of do not simultaneously reach their maximum constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号