territory

Time limit: 0.3s Memory limit: 1024MB Input: Output:

Due to her thirst for power, Sashka decided to create a new country. It will span across the territories of Bulgaria, which can be represented as a network of NN regions, numbered 11 to NN, connected by N1N-1 roads. From every region it is possible to reach every other region using the roads. Sashka’s country will span across several (one or more) regions such that they are connected. Regions are connected when there is a path between any two of the chosen regions on which no unchosen region lies.

The most recent census established that the ii-th region has aia_i inhabitants. Thus, the population of Sashka’s country will be the sum of the individual populations of the chosen regions. Since it would be terribly boring for Sashka to consider just one variant of her country, she will consider all possible ones. She wants to find the sum of the populations over all possible choices of country. Write a program territory that finds this value. Since the sum may be too large, find its remainder when divided by 998 244 353998 \ 244 \ 353.

Input data

On one line of standard input the positive integer NN is given. On the next line NN positive integers a1,a2,...,aNa_1, a_2, ..., a_N are given. On the remaining N1N-1 lines the road network is described: the ii-th of these lines contains the integers uiu_i and viv_i, characterising a road between region uiu_i and region viv_i.

Output data

On standard output print the required value.

Constraints and clarifications

  • 1N200 0001 \leq N \leq 200 \ 000
  • 1ai1071 \leq a_i \leq 10^7
  • 1ui,viN1 \leq u_i, v_i \leq N
Subtask Required subtasks Points NN Additional constraints
0 - 0 - Sample tests.
1 0 15 15\leq 15 -
2 - 10 200 000\leq 200 \ 000 ui=i,vi=i+1u_i = i, v_i = i+1
3 0-1 35 2 000\leq 2 \ 000 -
4 0-3 40 200 000\leq 200 \ 000 -

Example 1

stdin

6
1 4 9 16 25 36
1 2
2 3
3 4
4 5
5 6

stdout

812

Explanation

Bulgaria is indicated in the image.

Example 2

stdin

7
10 7 5 8 4 6 9
2 7
2 5
7 1
6 5
7 4
3 5

stdout

864

Explanation

Bulgaria is indicated in the image.

Log in or sign up to be able to send submissions!