#P5206. [WC2019] 数树
[WC2019] 数树
Description
This problem contains three questions:
- Question 0: The shapes of two trees with nodes are given (both trees have nodes labeled from to ). The first tree is the red tree, and the second tree is the blue tree. You need to assign each node an integer in such that for any two nodes , if there exists a path that belongs to both trees, then must be assigned the same number. Find the number of assignment schemes.
- The definition of “there exists a path that belongs to both trees” is the same as in the “Background”.
- Question 1: The blue tree is given. For all choices of the red tree, compute the sum of the answers to Question 0.
- Question 2: For all choices of the blue tree, compute the sum of the answers to Question 1.
Hint: There are different trees on nodes.
In different test points, you may need to answer different questions. We use to denote the index of the question you need to answer (corresponding to 0, 1, 2 above).
Since the answer may be very large, you only need to output it modulo .
Input Format
The first line contains three integers separated by spaces.
If , then the next lines follow: the first lines each describe a blue rope, and the next lines each describe a red rope.
If , then the next lines follow, each describing a blue rope.
If , then there is no further input.
Each rope description line contains two integers separated by a space, representing the indices of the two mice connected by this rope. The mice are numbered starting from .
Output Format
Output one integer, representing the answer modulo .
3 2 0
1 2
2 3
1 2
2 3
2
3 2 1
1 2
2 3
10
3 2 2
30
Hint
Sample Explanation 1
The two trees are the same, so any two nodes must be assigned the same number. The number of schemes is .
Sample Explanation 2
There are three possible red trees:
- Contains ropes (meaning the rope connecting mice and , similarly below), . Then any two mice must be assigned the same number, so the answer to Question 0 is .
- Contains ropes , . Then mice and must be assigned the same number, so the answer to Question 0 is .
- Contains ropes , . Then node and node must be assigned the same number, so the answer to Question 0 is .
Therefore, the answer to Question 1 is .
Sample Explanation 3
There are three possible blue trees. It is not hard to see that for each blue tree, the computed answer to Question 1 is . So the answer is .
::cute-table{tuack}
| Question Type | Test Point ID | Points per Test (CTT) | Points per Test (Non-CTT) | ||
|---|---|---|---|---|---|
| 0 | 1 | No special restriction | 2 | 18 | |
| ^ | 2 | ^ | ^ | 5 | |
| 3 | ^ | ^ | |||
| 1 | 4 | 1 | 4 | ||
| ^ | 5 | ^ | ^ | ||
| 6 | 6 | ||||
| 7 | ^ | ^ | |||
| 8 | |||||
| 9 | ^ | ||||
| 10 | 1 | ||||
| 11 | ^ | No special restriction | 5 | 2 | |
| 12 | ^ | ^ | |||
| 13 | |||||
| 14 | |||||
| 2 | 15 | 1 | 4 | ||
| ^ | 16 | ^ | ^ | ||
| 17 | 6 | ||||
| 18 | ^ | ^ | |||
| 19 | |||||
| 20 | ^ | ||||
| 21 | 1 | ||||
| 22 | ^ | No special restriction | 5 | 2 | |
| 23 | ^ | ||||
| 24 | |||||
| 25 | |||||
To optimize your reading experience, we placed the Test Point ID in the middle of the table; please pay attention to this.
All test points satisfy $3 \leq n \leq 10^{5}, 1 \leq y<998244353, o p \in\{0,1,2\}$.
Luogu scores according to CTT points
Translated by ChatGPT 5
京公网安备 11011102002149号