#P11362. [NOIP2024] 遗失的赋值

[NOIP2024] 遗失的赋值

Description

Xiao F has nn variables x1,x2,,xnx_1, x_2, \ldots, x_n. Each variable can take integer values from 11 to vv.

Xiao F added n1n - 1 binary constraints between these variables. The ii-th constraint (1in11 \leq i \leq n - 1) is: if xi=aix_i = a_i, then xi+1=bix_{i+1} = b_i must hold, where aia_i and bib_i are integers between 11 and vv. When xiaix_i \neq a_i, the ii-th constraint imposes no restrictions on xi+1x_{i+1}. Additionally, Xiao F added mm unary constraints, where the jj-th constraint (1jm1 \leq j \leq m) states xcj=djx_{c_j} = d_j.

Xiao F remembers all cjc_j and djd_j values but has forgotten all aia_i and bib_i 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 ai,bia_i, b_i (1in11 \leq i \leq n - 1) exist such that there is at least one valid assignment satisfying all constraints. Since the number might be large, output the result modulo 109+710^9 + 7.

Input Format

The problem contains multiple test cases.

The first line of input contains an integer TT, the number of test cases.

This is followed by TT test cases, each formatted as follows:

  • The first line contains three integers nn, mm, vv, representing the number of variables, the number of unary constraints, and the upper bound of variable values.
  • The next mm lines each contain two integers cjc_j, djd_j, describing a unary constraint.

Output Format

For each test case, output one line containing an integer, the number of valid combinations modulo 109+710^9 + 7.

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 (a1,b1)(a_1, b_1) combinations (1,1)(1,1), (1,2)(1,2), (2,1)(2,1), (2,2)(2,2) are valid. For example:

    • When (a1,b1)=(1,1)(a_1, b_1) = (1,1), (x1,x2)=(1,1)(x_1, x_2) = (1,1) satisfies all constraints.
    • When (a1,b1)=(2,2)(a_1, b_1) = (2,2), both (x1,x2)=(1,1)(x_1, x_2) = (1,1) and (x1,x2)=(1,2)(x_1, x_2) = (1,2) are valid.
  • Second test case: The only valid assignment is (x1,x2)=(1,2)(x_1, x_2) = (1,2). Thus:

    • (a1,b1)=(1,1)(a_1, b_1) = (1,1) is invalid (requires x2=1x_2=1), but the other three combinations are valid.
  • Third test case: No assignment satisfies both x1=1x_1=1 and x1=2x_1=2, 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 ii-th test case (1i101 \leq i \leq 10) satisfies the constraints for test point ii 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 ii-th test case (1i101 \leq i \leq 10) satisfies the constraints for test point i+10i + 10 in the data range.

Data Range

For all test data, it is guaranteed that:

  • 1T101 \leq T \leq 10,
  • 1n1091 \leq n \leq 10^9, 1m1051 \leq m \leq 10^5, 2v1092 \leq v \leq 10^9,
  • For all jj (1jm1 \leq j \leq m), 1cjn1 \leq c_j \leq n, 1djv1 \leq d_j \leq v.
Test Case nn \leq mm \leq vv \leq Special Property
1, 2 6 2 None
3 9
4, 5 12
6 10310^3 1 10310^3
7 10510^5 10510^5
8, 9 10910^9 10910^9
10 10310^3 A
11 10410^4
12 10510^5
13 10410^4 10310^3 10410^4 B
14 10610^6 10410^4 10610^6
15, 16 10910^9 10510^5 10910^9
17 10410^4 10310^3 10410^4 None
18 10610^6 10410^4 10610^6
19, 20 10910^9 10510^5 10910^9
  • Special Property A: m=nm = n and cj=jc_j = j for all jj (1jm1 \leq j \leq m).
  • Special Property B: dj=1d_j = 1 for all jj (1jm1 \leq j \leq m).

Translated by DeepSeek R1