#P5888. 传球游戏
传球游戏
Background
In Yangcheng, there are people who are good at playing cuju. During the Football Association Cup, at the northeast corner of the campus, two fields are set up. The cuju players stand in the field: people, one ball, two goals, three referees, that is all. The audience sits around. After a while, as soon as the whistle on the field blows, everyone becomes silent, and no one dares to make noise.
At that moment, the sound of passing, the faint sound of wind, the sound of players sprinting, the coach shouting, and the cheerleaders cheering all burst out together, and every wonderful sound is present. The whole audience stretches their necks, looks sideways, smiles, and sighs silently, thinking it is amazing.
Soon, one of our players makes a long pass. Their player intercepts it and charges toward our goal.
Then we see the goalkeeper oql standing at the goal, as if thinking about something.
Problem Description
It turns out he is thinking about this problem:
There are players standing in a circle, numbered from to . At the beginning, the ball is in the hands of player . There are passes in total. In each pass, the ball must be passed to someone, but it cannot be passed to oneself. Find the number of ways such that after the -th pass, the ball is passed back to player .
But he thinks this problem is too easy, so he adds restrictions. Each restriction is of the form , meaning that player cannot pass the ball to player .
To bring oql’s attention back to the match as soon as possible, you need to tell him this number of ways in the shortest time.
You only need to output the result modulo .
Input Format
The input consists of lines:
The first line contains three integers , which represent the number of players, the number of passes, and the number of restrictions.
The next lines each contain two integers , indicating that player cannot pass the ball to player .
The data guarantees that there do not exist different such that and .
Output Format
Output one integer, representing the number of valid ways for the ball to return to player after passes, modulo .
2 1 0
0
3 3 0
2
7 13 5
1 3
4 5
5 4
6 1
2 2
443723615
Hint
For of the data, .
For another of the data, .
For another of the data, .
For another of the data, .
For of the data, , , , , it is not guaranteed that and are different.
Translated by ChatGPT 5