#P11362. [NOIP2024] 遗失的赋值
[NOIP2024] 遗失的赋值
Description
Xiao F has variables . Each variable can take integer values from to .
Xiao F added binary constraints between these variables. The -th constraint () is: if , then must hold, where and are integers between and . When , the -th constraint imposes no restrictions on . Additionally, Xiao F added unary constraints, where the -th constraint () states .
Xiao F remembers all and values but has forgotten all and values. However, Xiao F knows that there exists an assignment to all variables that satisfies all constraints.
Now, Xiao F wants to determine how many possible combinations of () exist such that there is at least one valid assignment satisfying all constraints. Since the number might be large, output the result modulo .
Input Format
The problem contains multiple test cases.
The first line of input contains an integer , the number of test cases.
This is followed by test cases, each formatted as follows:
- The first line contains three integers , , , representing the number of variables, the number of unary constraints, and the upper bound of variable values.
- The next lines each contain two integers , , describing a unary constraint.
Output Format
For each test case, output one line containing an integer, the number of valid combinations modulo .
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2
4
3
0
Hint
Explanation for Sample #1
-
First test case: All possible combinations , , , are valid. For example:
- When , satisfies all constraints.
- When , both and are valid.
-
Second test case: The only valid assignment is . Thus:
- is invalid (requires ), but the other three combinations are valid.
-
Third test case: No assignment satisfies both and , so no valid combinations exist.
Sample #2
See files assign/assign2.in and assign/assign2.ans in the problem directory.
This sample contains 10 test cases, where the -th test case () satisfies the constraints for test point in the data range.
Sample #3
See files assign/assign3.in and assign/assign3.ans in the problem directory.
This sample contains 10 test cases, where the -th test case () satisfies the constraints for test point in the data range.
Data Range
For all test data, it is guaranteed that:
- ,
- , , ,
- For all (), , .
| Test Case | Special Property | |||
|---|---|---|---|---|
| 1, 2 | 6 | 2 | None | |
| 3 | 9 | |||
| 4, 5 | 12 | |||
| 6 | 1 | |||
| 7 | ||||
| 8, 9 | ||||
| 10 | A | |||
| 11 | ||||
| 12 | ||||
| 13 | B | |||
| 14 | ||||
| 15, 16 | ||||
| 17 | None | |||
| 18 | ||||
| 19, 20 | ||||
- Special Property A: and for all ().
- Special Property B: for all ().
Translated by DeepSeek R1
京公网安备 11011102002149号