#include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; using vi = vector; using vvi = vector>; using vvvi = vector>>; using vl = vector; using vvl = vector>; using vvvl = vector>>; using vm = vector; using vvm = vector>; using vvvm = vector>>; using ll = long long; template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, f, n) for (int i = (int) f; i < (int)(n); i++) #define repd(i, n, l) for (int i = (int) n; i >= (int) l; i--) #define all(p) p.begin(),p.end() vector> dydx{{-1, 0}, {1, 0}, {0, -1 }, {0, 1}}; const ll inf = 1LL << 60; void print(){ putchar(' '); } void print(bool a){ printf("%d", a); } void print(int a){ printf("%d", a); } void print(unsigned a){ printf("%u", a); } void print(long a){ printf("%ld", a); } void print(long long a){ printf("%lld", a); } void print(unsigned long long a){ printf("%llu", a); } void print(char a){ printf("%c", a); } void print(char a[]){ printf("%s", a); } void print(const char a[]){ printf("%s", a); } void print(float a){ printf("%.15f", a); } void print(double a){ printf("%.15f", a); } void print(long double a){ printf("%.15Lf", a); } void print(const string& a){ for(auto&& i : a) print(i); } template void print(const complex& a){ if(a.real() >= 0) print('+'); print(a.real()); if(a.imag() >= 0) print('+'); print(a.imag()); print('i'); } template void print(const vector&); template void print(const array&); template void print(const pair& p); template void print(const T (&)[size]); template void print(const vector& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } } template void print(const deque& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } } template void print(const array& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ putchar(' '); print(*i); } } template void print(const pair& p){ print(p.first); putchar(' '); print(p.second); } template void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ putchar(' '); print(*i); } } template void print(const T& a){ cout << a; } constexpr ll ten(int n){ return n==0?1:ten(n-1)*10; } vector> unweighted_graph(int n, int m){ vector> ret(n); while (m--){ int a, b; cin >> a >> b; a--; b--; ret[a].push_back(b); ret[b].push_back(a); } return ret; } vector>> weighted_graph(int n, int m){ vector>> ret(n); while (m--){ int a, b; long long c; cin >> a >> b >> c; a--, b--; ret[a].push_back({b, c}); ret[b].push_back({a, c}); } return ret; } template int argmin(vector &a){ T mi = *min_element(all(a)); for (int i = 0; i < a.size(); i++){ if (a[i] == mi) return i; } } template int argmax(vector &a){ T ma = *max_element(all(a)); for (int i = 0; i < a.size(); i++){ if (a[i] == ma) return i; } } mint ans = 0; void dfs(int n, int p, vvi &G, vm &dp, vm &A){ dp[n] = A[n]; // mint sm = 0; // int cnt = 0; for(int nxt : G[n]){ if (nxt == p) continue; // cnt++; dfs(nxt, n, G, dp, A); dp[n] += A[n] * dp[nxt]; } // if (cnt) dp[n] = sm * dp[n]; // else dp[n] = A[n]; // dp[n] += sm * A[n]; // cout << n << ' ' << dp[n].val() << endl; } void dfs2(int n, int p, vvi &G, vm &dp, vm &A){ ans += dp[n] - A[n]; // cout << n << ' ' << dp[n].val() << endl; for(int nxt : G[n]){ if (nxt == p) continue; mint pre = dp[n]; mint pre2 = dp[nxt]; dp[n] -= dp[nxt] * A[n]; dp[nxt] += dp[n] * A[nxt]; // if (G[n].size() > 1) dp[n] -= dp[nxt] * A[n]; // else dp[n] = A[n]; // if (G[nxt].size() > 1) dp[nxt] += dp[n] * A[nxt]; // else dp[nxt] = A[nxt] * dp[n]; // dp[nxt] += dp[n] * A[nxt]; dfs2(nxt, n, G, dp, A); dp[nxt] = pre2; dp[n] = pre; } } int main() { int N; cin >> N; vi a(N); rep(i, N) cin >> a[i]; vm A(N); rep(i, N) A[i] = a[i]; auto G = unweighted_graph(N, N-1); vm dp(N, 0); dfs(0, -1, G, dp, A); dfs2(0, -1, G, dp, A); ans *= mint(2).inv(); cout << ans.val() << endl; // rep(i, N) cout << dp[i].val() << ' '; return 0; }