时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
Special Judge, 64bit IO Format: %lld

题目描述

You are given a rooted tree with the root at node 1. Each edge in the tree can either be a solid edge or a virtual edge. A valid chain decomposition is defined as one where each node has at most one solid edge leading to its children.

Next, we define the operation access(u) :

1. For each node x on the chain from u to the root, set all edges leading towards its children to virtual edges.
2. Set all edges on the chain from u to the root to solid edges.

Initially, the entire tree T_0 consists of virtual edges. After n operations, T_i results from performing access(P_i) on T_{i-1}, where P is a permutation of integers from 1 to n.

Now, you are given the status of each edge on T_n. You want to determine how many permutations P exist such that performing operations in order according to P results in T_n.

Additionally, there are q modifications to T_n. Initially, T_n consists entirely of virtual edges. Each modification specifies a node u, and performs the access(u) operation on T_n. The modifications are not independent. After each modification, you need to output how many permutations P satisfy the sequence of operations to eventually obtain T_n. Answers should be given modulo 998244353.

输入描述:

The first line contains two positive integers n, q.

The second line contains n - 1 integers fa_2, fa_3, \cdots, fa_n, where fa_i denotes the parent node of node i.

The next q lines each contain a single integer u, indicating an access(u) operation on T_n.

输出描述:

There are q lines of output, each containing a single integer representing the answer after each modification.
示例1

输入

复制
8 9
1 2 1 2 5 5 2
6
2
6
8
3
1
1
5
8

输出

复制
5040
1680
5040
1680
1680
280
280
5040
1680

备注:

1 \leq n, q \leq 2 \times 10^5, 1 \leq fa_i, u \leq n.