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

题目描述

Falcom is a historical company whose work "Ys VIII -Lacrimosa of DANA-" is highly acclaimed.

Remoon wants to get the platinum trophy of this game for all versions, and he notices that the game has n versions, indexed from 1 to n. A quick way to achieve this is to copy data between different versions. Unfortunately, due to compatibility issues, data in each version cannot be loaded in other versions. Nevertheless, remoon gets n - 1 editors, where the i-th editor can rewrite data in version u_i, such that the rewritten data can be loaded in version v_i. It is also possible to use the i-th editor to change data in version v_i to data in version u_i. It is guaranteed that any two versions can transform into each other through the n - 1 editors.

To distinguish between each version, remoon gives each version j a magic integer a_j. If for any editor, . Then remoon can distinguish whether the editor has correctly rewritten a version or not. Besides, to limit the magic number's size, remoon gives an upper bound integer sequence b_1, ..., b_n and require that for , we have .

Remoon wonders how many ways to choose a_1, ..., a_n so that he can correctly distinguish between the versions. Two ways a_1,..., a_n and a_1', ..., a_n' are considered different if and only if there exists such that . As the answer may be too large, you only need to output the answer modulo 998244353.

输入描述:

The first line contains an integer , denoting the number of versions. 


The second line contains n integers , denoting the upper bound on the magic integer on each version.

Then n-1 lines follow, where the -th line contains two integers u_j and v_j, denoting the j-th editor can copy data between version u_j and v_j.

输出描述:

Output an integer in a line, denoting the answer taken modulo 998244353.
示例1

输入

复制
5
1 2 3 4 5
1 2
2 3
3 4
4 5

输出

复制
24