#P9773. [HUSTFC 2023] 序列配对
[HUSTFC 2023] 序列配对
Problem Description
You have a sequence of length : . Initially, every element in the sequence satisfies .
Then you are given pairs of indices. Each pair is an integer pair , meaning that and are paired. After each pairing, you must perform exactly one of the following two operations (you cannot do both):
- Increase by , then decrease by .
- Increase by , then decrease by .
You are also told that these pairings follow a special rule: among the integers appearing in the pairs, each index of the sequence appears exactly times.
You want to know, among all possible choices of operations, how many result in . Since the answer may be very large, output it modulo .
Input Format
The first line contains an integer , the length of the sequence.
The next lines each contain two integers , describing the -th pairing. It is guaranteed that these integers satisfy the requirement in the statement.
The last line contains an integer , with the meaning as described above.
Output Format
Output one integer: the number of operation plans such that , modulo .
3
1 3
2 3
1 2
0
2
6
2 5
3 6
2 5
4 6
1 3
1 4
8
28
Hint
Translated by ChatGPT 5