#include using namespace std; #include using namespace atcoder; using mint = modint998244353; int N; using Vi = std::vector ; using VVi = vector; using Vm = vector; Vm dp1, dp2; VVi gr; Vm A; void dfs(int s = 0, int p = -1) { dp1[s] = 0; dp2[s] = A[s]; mint sum = 1; for (int& v : gr[s]) { if (v == p) continue; dfs(v, s); dp1[s] += dp1[v]; dp2[s] += dp2[v] * A[s]; dp1[s] += sum * dp2[v] * A[s]; sum += dp2[v]; } } int main () { cin >> N; gr.resize(N); A.resize(N); dp1.resize(N); dp2.resize(N); for (auto& a : A) { int x; cin >> x; a = x; } for (int i = 1; i < N; i ++) { int a, b; cin >> a >> b; gr[--a].push_back(--b); gr[b].push_back(a); } dfs(); cout << dp1[0].val() << endl; }