atcoder#ARC121E. [ARC121E] Directed Tree

[ARC121E] Directed Tree

Score : 700700 points

Problem Statement

Given is a directed tree with NN vertices numbered 11 through NN.

Vertex 11 is the root of the tree. For each integer ii such that 2iN2 \leq i \leq N, there is a directed edge from Vertex pip_i to ii.

Let aa be the permutation of (1,,N)(1, \ldots, N), and aia_i be the ii-th element of aa.

Among the N!N! sequences that can be aa, find the number of sequences that satisfy the following condition, modulo 998244353998244353.

  • Condition: For every integer ii such that 1iN1 \leq i \leq N, Vertex ii is unreachable from Vertex aia_i by traversing one or more edges.

Constraints

  • All values in input are integers.
  • 1N20001 \leq N \leq 2000
  • 1pi<i1 \leq p_i < i

Input

Input is given from Standard Input in the following format:

NN

p2p_{2} \cdots pNp_N

Output

Print the number of sequences aa among the permutations of (1,,N)(1, \ldots, N) that satisfy the condition in Problem Statement, modulo 998244353998244353.

4
1 1 3
4
30
1 1 3 1 5 1 1 1 8 9 7 3 11 11 15 14 4 10 11 12 1 10 13 11 7 23 8 12 18
746746186
  • Remember to print the count modulo 998244353998244353.