#Lutece3003. 又是树上距离

又是树上距离

Migrated from Lutece 3003 又是树上距离

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

给一棵 nn 个点的树,每个点 ii 有点权 aia_i 。定义两个点 i,ji,j 之间的花费 cost(i,j)cost(i,j)aiajdis2(i,j)a_i\cdot a_j\cdot dis^2(i,j),其中 dis(i,j)dis(i,j) 表示节点 i,ji,j 在树上的距离。现在你需要对每个点 ii(j=1ncost(i,j))mod998244353(\sum_{j=1}^n cost(i,j))\mod 998244353 的值。

Input

第一行一个正整数 nn,表示树的节点个数。 第二行 nn 个正整数 a1,a2,,ana_1,a_2,\cdots,a_n,表示每个点的点权。 接下来 n1n-1 行,每行两个整数ui,vi(1ui,vin,uivi)u_i,v_i(1\le u_i,v_i\le n,u_i\neq v_i),表示点ui,viu_i,v_i之间有一条边。

Output

输出 nn 行,第 ii 行表示第 ii 个数的答案。

Samples

5
1 2 3 4 5
1 2
1 5
2 3
2 4
35
56
201
252
360

Constraints

2n1052\le n\le 10^5,1ai1091\le a_i\le10^9

Note

对于样例中的3号节点,其距离1,2,3,4,5号节点的距离分别为 2,1,0,2,32,1,0,2,3,因此对应的答案为 $3\times 1\times 2^2+3\times 2\times 1^2+3\times 3\times 0^2+3\times 4\times 2^2+3\times 5\times 3^2=12+6+0+48+135=201$.

Resources

2023 UESTC ICPC Training for Search and Dynamic Programming