Ex - Antichain

AtCoder
IDabc269_h
Time8000ms
Memory256MB
Difficulty
We have a rooted tree $T$ with $N$ vertices numbered $1$ to $N$. Vertex $1$ is the root, and the parent of vertex $i$ $(2 \leq i \leq N)$ is vertex $P_i$. A non-empty subset $S$ of the vertex set $V = \lbrace 1, 2,\dots, N\rbrace$ of $T$ is said to be a **good vertex set** when it satisfies the following condition. * For every pair of different vertices $(u, v)$ in $S$, the following holds: $u$ is not an ancestor of $v$. For each $K = 1, 2, \dots, N$, find the number, modulo $998244353$, of good vertex sets with exactly $K$ vertices. ## Constraints * $2 \leq N \leq 2 \times 10^5$ * $1 \leq P_i \lt i$ * All values in the input are integers. ## Input The input is given from Standard Input in the following format: $N$ $P_2$ $P_3$ $\dots$ $P_N$ [samples]
Samples
Input #1
4
1 2 1
Output #1
4
2
0
0

For each $1 \leq K \leq N$, the good vertex sets of size $K$ are listed below.

*   $K=1$: $\lbrace 1 \rbrace, \lbrace 2 \rbrace, \lbrace 3 \rbrace, \lbrace 4 \rbrace$.
*   $K=2$: $\lbrace 2, 4 \rbrace, \lbrace 3, 4 \rbrace$.
*   $K=3,4$: There is none.
Input #2
6
1 1 2 2 5
Output #2
6
6
2
0
0
0
Input #3
6
1 1 1 1 1
Output #3
6
10
10
5
1
0
Input #4
10
1 2 1 2 1 1 2 6 9
Output #4
10
30
47
38
16
3
0
0
0
0
API Response (JSON)
{
  "problem": {
    "name": "Ex - Antichain",
    "description": {
      "content": "We have a rooted tree $T$ with $N$ vertices numbered $1$ to $N$. Vertex $1$ is the root, and the parent of vertex $i$ $(2 \\leq i \\leq N)$ is vertex $P_i$. A non-empty subset $S$ of the vertex set $V =",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 8000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc269_h"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a rooted tree $T$ with $N$ vertices numbered $1$ to $N$. Vertex $1$ is the root, and the parent of vertex $i$ $(2 \\leq i \\leq N)$ is vertex $P_i$.\nA non-empty subset $S$ of the vertex set $V =...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments