8597: Everlasting Transeunt

内存限制:1024 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

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 ui, such that the rewritten data can be loaded in version vi. It is also possible to use the i-th editor to change data in version vi to data in version ui. It is guaranteed that any two versions can transform into each other through the n1 editors.

To distinguish between each version, remoon gives each version j a magic integer aj. If for any editor, aui≠avi. 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 b1,...,bn and require that for i∈{1,2,...,n}, we have 1≤ai≤bi.

Remoon wonders how many ways to choose a1,...,an so that he can correctly distinguish between the versions. Two ways a1,...,an and a1′,...,an are considered different if and only if there exists 1≤i≤n such that ai≠ai. As the answer may be too large, you only need to output the answer modulo 998244353.

输入格式

The first line contains an integer n(1≤n≤5×105), denoting the number of versions.

The second line contains n integers b1,b2,…,bn(1≤bi<998244353), denoting the upper bound on the magic integer on each version.
Then n−1 lines follow, where the j(1≤j≤n−1)-th line contains two integers uj and vj, denoting the j-th editor can copy data between version uj and vj.

输出格式

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

输入样例 复制

5
1 2 3 4 5
1 2
2 3
3 4
4 5

输出样例 复制

24