题目描述
Background
Nauuo is a problem setter.
It is well known that some problem setters are very lazy, leading to brute force searches with an optimality pruning being sufficient to pass. Nauuo has decided to thwart these naive brute force methods.
Problem Description
Nauuo has decided to thwart a brute force search program by constructing a set of data. To simplify the problem, you will be given the search tree $T$ generated by this data. $T$ contains $n$ nodes, numbered from $1$ to $n$, where node $1$ is the root of $T$. The depth of a node is the number of nodes on the simple path from it to node $1$.
The pseudocode of the 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 the assignment operation.
In simpler terms, this brute force program will traverse the search tree in a depth-first manner. When it reaches a leaf node, it will update the answer with the depth of this leaf node.
Additionally, the program has an optimality pruning, meaning that when it encounters any node with a depth equal to the answer, it will not visit the children of this node.
Unfortunately, Nauuo does not know the order in which the program visits the children of a node, so she assumes that the order is uniformly random among all possible permutations, which totals $\prod d_i!$ cases, where $d_i$ is the number of children of node $i$.
Now, she wants to know the expected number of nodes visited by the program to determine if her data will thwart the program.
To avoid floating-point errors, the answer should be taken modulo $998244353$. It is guaranteed that the answer can be expressed as a simplified fraction $\frac{p}{q}$, and you only need to output an integer $x$ such that $0 \leq x < 998244353$ and $\equiv p \pmod{998244353}$.
Input Format
The first line contains an integer $n$.
The second line contains $n-1$ integers $p_2, p_3, \ldots, p_n$, where $p_i$ denotes the parent node of node $i$.
Output Format
A single integer, the required $x$.
Sample Input and Output
Sample Input #1
4
1 1 3
Sample Output #1
499122180
Sample Input #2
3
1 2
Sample Output #2
3
Sample Input #3
13
1 1 1 3 5 4 2 3 7 4 4 6
Sample Output #3
776412285
Notes
Sample Explanation
For the first sample, the true answer is $\frac{7}{2}$.
There are only two possible cases: if node $1$ first traverses node $3$, the program will visit all nodes in the search tree. If node $1$ first traverses node $2$, node $4$ will not be visited.
For the second sample, each non-leaf node has a unique child, so there is only one possible case, and all nodes are necessarily visited.
For the third sample, the true answer is $\frac{94}{9}$.
Data Range
This problem uses batched testing.
For all test cases, it is guaranteed that $1 \leq n \leq 3 \times 10^5$ and $1 \leq p_i < i$.
- Subtask 1 (11 pts) $n \leq 9$.
- Subtask 2 (18 pts) $n \leq 100$.
- Subtask 3 (19 pts) $n \leq 1000$.
- Subtask 4 (4 pts) $p_i = i-1$.
- Subtask 5 (8 pts) $p_i = \lfloor \frac{i}{2} \rfloor$.
- Subtask 6 (40 pts) No additional constraints.
Hints
If you do not know how to take a fraction modulo, you can refer to this.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分