Forethought Future Cup - Elimination Round
F
Leaf Partition
Codeforces
2500
原题
← EG →
翻译中…

You are given a rooted tree with $n$ nodes, labeled from $1$ to $n$. The tree is rooted at node $1$. The parent of the $i$-th node is $p_i$. A leaf is node with no children. For a given set of leaves $L$, let $f(L)$ denote the smallest connected subgraph that contains all leaves $L$.

翻译中…

You would like to partition the leaves such that for any two different sets $x, y$ of the partition, $f(x)$ and $f(y)$ are disjoint.

翻译中…

Count the number of ways to partition the leaves, modulo $998244353$. Two ways are different if there are two leaves such that they are in the same set in one way but in different sets in the other.

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($2 \leq n \leq 200\,000$) — the number of nodes in the tree.

翻译中…

The next line contains $n-1$ integers $p_2, p_3, \ldots, p_n$ ($1 \leq p_i \lt i$).

翻译中…

Output

翻译中…

Print a single integer, the number of ways to partition the leaves, modulo $998244353$.

翻译中…

Note

翻译中…

In the first example, the leaf nodes are $2,3,4,5$. The ways to partition the leaves are in the following image image

翻译中…

In the second example, the only leaf is node $10$ so there is only one partition. Note that node $1$ is not a leaf.

翻译中…

样例

Input #1
5
1 1 1 1
Output #1
12
InputCopy OutputCopy
Input #2
10
1 2 3 4 5 6 7 8 9
Output #2
1
InputCopy OutputCopy
题目信息
题号
1146F
时间限制
1 s
内存限制
256 MB
标签
动态规划
树

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