#include #include using namespace std; using mint = atcoder::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] = mint::raw(v); } vector> g(n); for(int i = 1; i < n; i++){ cin >> u >> v; g[--u].emplace_back(--v); g[v].emplace_back(u); } mint ans; auto dfs = [&](auto dfs, int v, int p = -1) -> mint { mint s0, s1; for(auto &&u : g[v]){ 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'; }