#P6383. 『MdOI R2』Resurrection
『MdOI R2』Resurrection
Background
If you are not clear about some definitions in this problem, you can read the [Notes / Hint] section.
Problem Description
There is a tree with nodes, and all its edges are numbered from to in order.
It is guaranteed that for any node in , the simple path from to node does not pass through any node whose index is less than .
Generate an undirected graph with nodes by the following steps:
Choose a permutation of , and then perform operations in order. In the -th operation, first delete the edge in tree whose index is . Then let and be, respectively, the node with the largest index among all nodes currently connected to and to in the current tree . Add an edge between node and node in graph .
For the given tree , find how many essentially different graphs can be generated in total by the method above. Graphs and are essentially different if and only if there exist and such that edge does not exist in , but exists in .
Since the answer may be very large, you only need to output it modulo .
Input Format
The first line contains one integer , the number of nodes in tree .
The next lines each contain two integers . In the -th line, it means the edge in with index is .
Output Format
Output one integer: the answer modulo .
4
1 4
2 3
3 4
2
11
1 4
2 6
3 11
4 6
5 6
6 7
7 9
8 9
9 10
10 11
4605
Hint
【Help and Hint】
To make it easier for contestants to test their code, this problem additionally provides an extra sample for contestants to use.
【Sample Explanation】
In sample 1, the possible graphs that can be generated are shown in the figure:

When , the graph on the right will be generated; otherwise, the graph on the left will be generated.
For sample 2, I have a wonderful explanation, but unfortunately this blank space is too small to write it down.
【Constraints】
This problem uses bundled tests.
For all testdata, it is guaranteed that , .
It is guaranteed that the input edges form a tree, and for any node , the simple path from to node does not pass through any node whose index is less than .
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| Subtask 1 | None | ||
| Subtask 2 | |||
| Subtask 3 | All nodes are directly connected to node | ||
| Subtask 4 | The tree is a chain | ||
| Subtask 5 | None | ||
| Subtask 6 |
Below are some definitions used in this problem:
-
A tree is an undirected connected graph with nodes and edges.
-
Edge means an edge connecting node and node .
-
A path is a sequence such that for any , edge exists in , and has not been deleted by previous operations.
-
Nodes and are connected if and only if there exists a path such that and . Every node is connected to itself.
Translated by ChatGPT 5