#P6383. 『MdOI R2』Resurrection

    ID: 6901 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP树形数据结构构造洛谷月赛

『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 TT with nn nodes, and all its edges are numbered from 11 to n1n-1 in order.

It is guaranteed that for any node uu in TT, the simple path from uu to node nn does not pass through any node whose index is less than uu.

Generate an undirected graph GG with nn nodes by the following steps:

Choose a permutation pp of 1n11 \sim n-1, and then perform n1n-1 operations in order. In the ii-th operation, first delete the edge (a,b)(a,b) in tree TT whose index is pip_i. Then let uu and vv be, respectively, the node with the largest index among all nodes currently connected to aa and to bb in the current tree TT. Add an edge between node uu and node vv in graph GG.

For the given tree TT, find how many essentially different graphs GG can be generated in total by the method above. Graphs G1G_1 and G2G_2 are essentially different if and only if there exist uu and vv such that edge (u,v)(u,v) does not exist in G1G_1, but exists in G2G_2.

Since the answer may be very large, you only need to output it modulo 998244353998244353.

Input Format

The first line contains one integer nn, the number of nodes in tree TT.

The next n1n-1 lines each contain two integers u,vu, v. In the ii-th line, it means the edge in TT with index ii is (u,v)(u,v).

Output Format

Output one integer: the answer modulo 998244353998244353.

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 Input Sample Output


【Sample Explanation】

In sample 1, the possible graphs GG that can be generated are shown in the figure:

When p={1,2,3},{2,1,3},{2,3,1}p = \{1,2,3\},\{2,1,3\},\{2,3,1\}, 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 1n3×1031 \leq n \leq 3 \times 10^3, 1u,vn1 \leq u,v \leq n.

It is guaranteed that the input edges form a tree, and for any node uu, the simple path from uu to node nn does not pass through any node whose index is less than uu.

Subtask ID nn\leq Special Property Score
Subtask 1 55 None 3232
Subtask 2 1414 1616
Subtask 3 10310^3 All nodes are directly connected to node nn 11
Subtask 4 The tree is a chain 77
Subtask 5 5050 None 2222
Subtask 6 3×1033 \times 10^3

Below are some definitions used in this problem:

  • A tree is an undirected connected graph with nn nodes and n1n-1 edges.

  • Edge (u,v)(u,v) means an edge connecting node uu and node vv.

  • A path is a sequence p1,p2pkp_1,p_2 \ldots p_k such that for any 1i<k1 \leq i < k, edge (pi,pi+1)(p_i,p_{i+1}) exists in TT, and has not been deleted by previous operations.

  • Nodes uu and vv are connected if and only if there exists a path p1,p2pkp_1,p_2 \ldots p_k such that p1=up_1=u and pk=vp_k=v. Every node is connected to itself.

Translated by ChatGPT 5