#P3631. [APIO2011] 方格染色
[APIO2011] 方格染色
Description
Sam and his sister Sara have a grid with cells. They want to color each cell either red or blue. Due to personal preference, they want every square in the grid to contain an odd number ( or ) of red cells. For example, the following is a valid coloring (R stands for red, B stands for blue):
B B R B R
R B B B B
R R B R B
However, last night, someone already colored some cells! Now Sam and Sara are very upset. Still, they want to know whether it is possible to color the remaining cells so that the entire grid still satisfies their requirement. If it is possible, how many such colorings are there?
Input Format
The first line contains three integers , representing the number of rows, the number of columns, and the number of precolored cells, respectively.
The next lines describe the precolored cells. The -th line contains three integers , representing the row index, the column index, and the color of the -th precolored cell, respectively. means the cell is red, and means the cell is blue.
Output Format
Output a single integer: the value of modulo , where is the number of valid colorings.
3 4 3
2 2 1
1 2 0
2 3 1
8
Hint
For of the testdata, .
For of the testdata, , .
For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号