#P1446. [HNOI2008] Cards
[HNOI2008] Cards
Description
Xiaochun is quite idle. Facing cards on the desk, he decides to color each card. He currently has colors: red, blue, and green. He asks Sun how many colorings there are, and Sun quickly gives the answer.
Furthermore, Xiaochun requires exactly red, blue, and green cards. He asks again how many colorings there are; Sun thinks for a moment and gives the correct answer. Finally, Xiaochun invents different shuffles. He asks Sun how many essentially different colorings there are now. Two colorings are considered the same if and only if one can be transformed into the other by applying arbitrary shuffles (that is, you may use multiple shuffles, and each shuffle may be used multiple times).
Sun finds this problem somewhat challenging and decides to leave it to you. Since the answer may be large, you only need to output the result modulo . It is guaranteed that is a prime.
Description
Input Format
The first line contains integers: (with ). Here, the mentioned in the statement is , i.e., .
The next lines each describe a shuffle. Each line has space-separated integers , guaranteed to be a permutation of to , meaning that when using this shuffle, position becomes the card that was originally at position . The input guarantees that any number of shuffles can be replaced by one of these shuffles, and that for every shuffle, there exists a shuffle that brings you back to the original state.
Also, for of the testdata, .
Output Format
Output the number of distinct colorings modulo .
1 1 1 2 7
2 3 1
3 1 2
2
Hint
There are essentially different colorings: RGB and RBG. Using shuffle 231 once gives GBR and BGR; using shuffle 312 once gives BRG and GRB.
Translated by ChatGPT 5
京公网安备 11011102002149号