#include #if __has_include() #include using namespace atcoder; #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using mint = modint998244353; int main() { cin.tie(nullptr) -> sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; vector> to(n); rep(i, n-1) { int u, v; cin >> u >> v; --u; --v; to[u].push_back(v); to[v].push_back(u); } mint ans; vector dp(n); auto dfs = [&](auto& f, int v, int p=-1) -> void { dp[v] = a[v]; for (int u : to[v]) { if (u == p) continue; f(f, u, v); ans += dp[v]*dp[u]; dp[v] += dp[u]*a[v]; } }; dfs(dfs, 0); cout << ans.val() << '\n'; return 0; }