NOMURA プログラミングコンテスト 2021 (AtCoder Regular Contest 121)
E
Directed Tree
AtCoder
⌀ 2645
原题
← DF →
翻译中…

Problem Statement

翻译中…

Given is a directed tree with $N$ vertices numbered $1$ through $N$.

翻译中…

Vertex $1$ is the root of the tree. For each integer $i$ such that $2 \leq i \leq N$, there is a directed edge from Vertex $p_i$ to $i$.

翻译中…

Let $a$ be the permutation of $(1, \ldots, N)$, and $a_i$ be the $i$-th element of $a$.

翻译中…

Among the $N!$ sequences that can be $a$, find the number of sequences that satisfy the following condition, modulo $998244353$.

翻译中…
  • Condition: For every integer $i$ such that $1 \leq i \leq N$, Vertex $i$ is unreachable from Vertex $a_i$ by traversing one or more edges.
翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $1 \leq N \leq 2000$
  • $1 \leq p_i < i$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
p_{2} \cdots p_N

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
4
1 1 3
Output #1
4
Input #2
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
Output #2
746746186
- Remember to print the count modulo $998244353$.
题目信息
题号
arc121_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。