#P6048. 最优性剪枝

    ID: 4438 远端评测题 4000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索数学2020线段树剪枝树链剖分,树剖期望

最优性剪枝

Description

Nauuo decides to break a brute-force search program, so she constructs a set of testdata. To simplify the problem, you are given the search tree TT generated by this testdata. TT contains nn nodes, numbered 1n1 \sim n in order, where node 11 is the root of TT. The depth of a node is the number of nodes on the simple path from it to node 11.

The pseudocode of this program is as follows.

answer := inf

procedure dfs(node,depth)
	if (node is leaf) 
		answer := min(answer,depth)
		return
	if (depth < answer)
		for i in children of node
			dfs(i,depth+1)

dfs(1,1)

Here, := denotes assignment.

In plain words, this brute-force search program traverses the search tree in depth-first order. When it reaches a leaf node, it updates the answer using the depth of that leaf node.

Meanwhile, this program has an optimality pruning. That is, when the program reaches any node whose depth equals the current answer, it will not visit this node’s children.

However, poor Nauuo does not know the order in which the program visits a node’s children. Therefore, she assumes that for each node, the order of visiting its children is uniformly random among all possible orders. Clearly, there are di!\prod d_i! possible cases in total, where did_i is the number of children of node ii.

Now she wants to know the expected number of nodes visited by this program, to determine whether the program will be broken by her testdata.

To avoid floating-point errors, take the answer modulo 998244353998244353. The answer is guaranteed to be representable as an irreducible fraction pq\frac{p}{q}. You only need to output an x(0x<998244353)x (0\leq x < 998244353) such that qxp(mod998244353)qx \equiv p \pmod {998244353}.

Input Format

The first line contains an integer nn.

The second line contains n1n-1 integers p2,p3pnp_2, p_3 \cdots p_n, where pip_i is the index of the parent of node ii.

Output Format

One line with an integer, the required xx.

4
1 1 3
499122180
3
1 2
3
13
1 1 1 3 5 4 2 3 7 4 4 6
776412285

Hint

Sample Explanation

For the first sample, the true answer is 72\frac{7}{2}.

There are only two cases in total. If node 11 traverses node 33 first, then the program will visit all nodes in the search tree. If node 11 traverses node 22 first, then node 44 will not be visited.

In the second sample, each non-leaf node has only one child, so there is only one possible case, and all nodes will definitely be visited.

For the third sample, the true answer is 949\frac{94}{9}.


Constraints

This problem uses bundled test cases.

For all test points, it is guaranteed that 1n3×1051 \leq n \leq 3\times 10^5, 1pi<i1 \leq p_i < i.

Subtask 1 (11 pts)\text{Subtask 1 (11 pts)} n9n \leq 9.

Subtask 2 (18 pts)\text{Subtask 2 (18 pts)} n100n \leq 100.

Subtask 3 (19 pts)\text{Subtask 3 (19 pts)} n103n\leq 10^3.

Subtask 4 (4 pts)\text{Subtask 4 (4 pts)} pi=i1p_i = i-1.

Subtask 5 (8 pts)\text{Subtask 5 (8 pts)} pi=i2p_i =\lfloor \frac{i}{2} \rfloor.

Subtask 6 (40 pts)\text{Subtask 6 (40 pts)} No special constraints.


Hint

If you do not know how to take a fraction modulo a number, you can refer to here.

Translated by ChatGPT 5