#P3581. [POI 2015 R1] 圆桌巫师 Sorcerers of the Round Table
[POI 2015 R1] 圆桌巫师 Sorcerers of the Round Table
Description
There are people (numbered ) sitting in a circle around a round table. For any two people sitting in adjacent seats, the absolute difference of their numbers must not exceed . Among them, some people dislike others. If dislikes , then cannot sit in the seat immediately to the right of . Now, assuming the seat of person has been fixed, how many valid seating arrangements are there for the remaining people?
Input Format
The first line contains three integers (, , ).
The next lines each contain two integers (, ), meaning dislikes . The same pair will not be repeated.
Output Format
Output a single integer, which is the number of valid arrangements modulo .
5 2 3
1 3
5 4
6
Hint
Original title: Czarnoksiężnicy okrągłego stołu.
Translated by ChatGPT 5
京公网安备 11011102002149号