#include #include using namespace std; using namespace atcoder; using mint = modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, u, v; cin >> n; vector a(n); for(int i = 0; i < n; i++){ cin >> v; a[i] = v; } vector> edge(2 * (n - 1)); for(int i = 0; i + 1 < n; i++){ cin >> u >> v; edge[2 * i] = make_pair(--u, --v); edge[2 * i + 1] = make_pair(v, u); } internal::csr g(n, edge); mint ans; auto dfs = [&](auto dfs, int v, int p = -1) -> mint { mint s0, s1; for(int i = g.start[v]; i < g.start[v + 1]; i++) { int u = g.elist[i]; if(u == p) continue; auto rc = dfs(dfs, u, v); s1 += s0 * rc; s0 += rc; } ans += (s0 + s1) * a[v]; return ++s0 * a[v]; }; dfs(dfs, 0); cout << ans.val() << '\n'; }