E. Easy Tree
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Given a tree with $$$n$$$ nodes, each node has a color black or white, and also given $$$q$$$ queries:

  • $$$v$$$ — change the color of node $$$v$$$, from black to white or vice versa.

Let's call a subset of nodes $$$S$$$ connected if for any two nodes $$$(v, u)$$$ from $$$S$$$, all nodes on the path between $$$v$$$ and $$$u$$$ are also in $$$S$$$.

Let's call a subset of nodes $$$S$$$ monochromatic if all nodes from $$$S$$$ have the same color.

After each query, print the number of connected monochromatic subsets (modulo $$$998\,244\,353$$$, obviously).

Input

The first line contains two integers $$$n$$$ and $$$q$$$ $$$(2 \le n \le 2 \times 10^5, 1 \le q \le 2 \times 10^5)$$$ — the size of the tree and the number of queries.

The second line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ $$$(0 \le c_i \le 1)$$$ — initial colors of nodes.

The next $$$n - 1$$$ lines contain two integers $$$v$$$ and $$$u$$$ $$$(1 \le v, u \le n)$$$ — edges of the tree.

The next $$$q$$$ lines contain one integer $$$v$$$ $$$(1 \le v \le n)$$$ — node from the query.

Output

Print $$$q$$$ integers — the number of connected monochromatic subsets modulo $$$998\,244\,353$$$ after each query.

Example
Input
6 5
1 0 0 0 0 1
4 3
4 5
1 2
2 4
4 6
1
2
5
4
2
Output
18
9
7
13
10