#P7159. 「dWoi R1」Sweet Fruit Chocolate

「dWoi R1」Sweet Fruit Chocolate

Description

Tojo makes the chocolate she wants to pour into a “chocolate fountain tree”. The chocolate fountain tree is a tree with nn nodes. Each node has a Sisyphus fruit. For each node uu, you have two choices: you can place aua_u fruits at node uu, or place no fruit at all. Then, Tojo will pour chocolate syrup from the root downward. The nutrition value that node uu brings to Saihara is the number of Sisyphus fruits placed in uu and its subtree. Tojo wants to know, among all 2n2^n fruit-placement plans, what is the total sum of Saihara’s nutrition values. Output the answer modulo 998244353998244353.

The root of the tree is node 11.

Input Format

The first line contains a positive integer nn.

The second line contains nn positive integers aia_i.

In the next n1n - 1 lines, each line contains two positive integers u,vu, v (1u,vn)(1\le u, v\le n), indicating that there is an edge (u,v)(u, v) in the tree.

Output Format

One line containing an integer representing the answer.

3
1 1 2
1 2
2 3
36

Hint

Sample 1 Explanation

Use SS to represent the selected state.

  • S=000S = 000 contributes 00.
  • S=001S = 001 contributes 11.
  • S=010S = 010 contributes 22.
  • S=011S = 011 contributes 33.
  • S=100S = 100 contributes 66.
  • S=101S = 101 contributes 77.
  • S=110S = 110 contributes 88.
  • S=111S = 111 contributes 99.

Constraints

For 20%20\% of the testdata, n20n \le 20.

For another 30%30\% of the testdata, u=v1u = v - 1.

For 100%100\% of the testdata, 2n1062 \le n \le 10^6, 1ai1091 \le a_i \le 10^9.

Translated by ChatGPT 5