#P4019. 多边形染色
多边形染色
Description
Flokirie has a beautiful convex -gon with vertices numbered from to . Each edge connects vertex and , and in particular, vertex is connected to vertex .
He wants to color each vertex with some color (), i.e., each vertex is assigned a color from to , and adjacent vertices must not have the same color.
He wants to know how many feasible colorings there are. He calculated it on paper and solved it in minutes.
He thought that was too trivial, so he defined the following “fancy” operations:
1 x p: vertex must be colored with color .2 x p: vertex must not be colored with color .3 x y: change the attribute of the edge between vertex and vertex (guaranteed that and ), i.e., vertex must have the same color as vertex .
Now, he wants to know the total number of feasible colorings after applying all operations. Since the result may be large, output it modulo .
Input Format
The first line contains three positive integers , , , representing the number of sides of the polygon, the number of operations, and the number of colors.
Each of the following lines contains three positive integers describing one operation, as defined above.
Output Format
Output a single integer: the number of feasible colorings modulo .
3 0 3
6
5 2 5
2 3 4
3 2 3
208
Hint
| Test Point ID | |||
|---|---|---|---|
It is guaranteed that for of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号