問題一覧 > 通常問題

No.3449 Mex of Subtree

レベル : / AI推定難易度 : 2500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 35
作問者 : 👑 potato167 / テスター : noya2
お気に入りにしたユーザー ProblemId : 12388 / 自分の提出
問題文最終更新日: 2026-02-16 04:46:30
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 493 (順位表) の他の問題:

Problem Statement

You are given a rooted tree with $N$ vertices, numbered from $1$ to $N$.

Vertex $1$ is the root, and the parent of vertex $i(2\leq i \leq N)$ is $P_{i}(1\leq P_{i}<i)$.

Find the number, modulo $998244353$, of non-negative integer sequences $A = (A_{1}, A_{2}, \dots , A_{N})$ of length $N$ that satisfy the following condition.

  • There exists a way to write $1$ non-negative integer on each of the $N$ vertices such that the following holds for every vertex $i(1\leq i\leq N)$.
    • The smallest non-negative integer not written on any vertex in the subtree of vertex $i$ (including $i$ itself) is $A_{i}$.

Constraints

  • $2\leq N\leq 5000$
  • $1\leq P_{i}<i(2\leq i \leq N)$
  • All input values are integers.

Input

The input is given from standard input in the following format.

$N$
$P_{2}$ $P_{3}$ $\cdots$ $P_{N}$

Output

Output the answer.

Sample

Sample 1
Input
2
1
Output
5

When $A = (2, 0)$, it can be shown that the condition is satisfied by writing $0$ on vertex $1$ and $1$ on vertex $2$.

The sequences $A$ satisfying the condition are the following $5$: $(0, 0), (1, 0), (1, 1), (2, 0), (2, 1)$, so output $5$.

Sample 2
Input
4
1 1 1
Output
28
Sample 3
Input
10
1 1 3 1 2 3 1 6 7
Output
9744

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。