#P5289. [十二省联考 2019] 皮配
[十二省联考 2019] 皮配
Description
This season, “China’s Best Coder” invites student elites from all over the country to compete. They come from different schools in cities nationwide (cities are numbered from to , and schools are numbered from to ). The city index of school is , and there are contestants from this school.
Besides the total size limits mentioned in Background, the mentor selection stage this season has additional rules:
- All contestants from the same city must join the same camp.
- All contestants from the same school must choose the same mentor.
For mentors, students from most schools have no preference. However, there are schools where, for each such school, the students have exactly one mentor they dislike. Students in the same school dislike the same mentor, and they will not join the team of the mentor they dislike.
With so many rules and preferences, as a loyal viewer you want to compute: after all contestants have chosen teams, how many different final outcomes are possible?
- Two outcomes are considered different if and only if there exists a school such that, in the two outcomes, contestants from this school join teams led by different mentors.
- Since the answer may be large, output it modulo .
Input Format
Each test file contains multiple test cases. The first line contains a non-negative integer indicating the number of test cases. Then each test case is described as follows:
- Line : two positive integers , , representing the number of schools and the number of cities.
- Line : four positive integers , , , , representing the four limits described in the statement.
- Next lines, each with two positive integers:
- On line of this part, the two numbers are , , representing the city of school and its number of contestants.
- It is guaranteed that , . Here .
- Next line: a non-negative integer , the number of schools with preferences.
- Next lines, each with two integers , , describing that contestants from school have a preference:
- Here is an integer from to , describing the mentor disliked by this school: means Yazid, means Little R, means Zayid, means Big R.
- It is guaranteed that , and all are distinct.
For each input line, if it contains multiple numbers, they are separated by a single space.
Output Format
Output the answer for each test case in order:
- For each test case, output one line with one integer, the number of possible outcomes modulo .
2
2 1
3 2 2 2
1 1
1 2
1
1 0
4 2
10 30 20 30
1 6
2 4
1 7
2 4
2
2 3
3 1
1
22
Hint
Sample 1 Explanation
For the st test case:
- The only city contains a total of contestants, but the total size limit of the Red camp is , so it cannot hold these contestants. Therefore, they are forced to choose the Blue camp.
- Based on this, since contestants from school dislike mentor Yazid, they must join mentor Little R in the R faction.
- Because the total size limit of the R faction is , mentor Little R’s team cannot hold the contestants from school , so they are forced to join mentor Yazid’s team.
- Therefore, there is only one possible outcome.
For the nd test case:
- An obvious fact is that all contestants in city cannot join the Blue camp, because the total number of contestants in city exceeds the total size limit of the Blue camp, so they are forced to all join the Red camp.
- If contestants from city join the Blue camp, a small calculation shows there are possible outcomes.
- If contestants from city join the Red camp, a small calculation shows there are possible outcomes.
- Therefore, the number of possible outcomes is .
Constraints and Notes
::cute-table{tuack}
| Test point | ||||
|---|---|---|---|---|
| ^ | ||||
| ^ | ||||
| ^ | ||||
| ^ | ||||
| ^ | ^ | |||
| ^ | ||||
| ^ | ||||
| ^ | ^ | |||
Here, .
For all test points, it is guaranteed that .
For each test case in all test points, it is guaranteed that , , , .
Also, note that the testdata does not guarantee that all cities have participating schools.
Additional Hint
There are also two additional sample files. Please download them from the attachments.
A warm reminder from the Twelve Provinces Joint Exam problem committee:
There are thousands of testdata, clearing arrays is the first rule.
If you forget to clear in multiple tests, you will cry with a zero score.
Translated by ChatGPT 5
京公网安备 11011102002149号