#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL mint dp[200005]; mint a[200005]; mint ans = 0; void dfs(int cv,int pv,vector> &E){ mint sum = 0; mint s2 = 0; rep(i,E[cv].size()){ int to = E[cv][i]; if(to==pv)continue; dfs(to,cv,E); sum += dp[to]; s2 -= dp[to]*dp[to]; } s2 += sum * sum; s2 /= 2; ans += s2 * a[cv]; ans += sum * a[cv]; dp[cv] = sum*a[cv] + a[cv]; } int main(){ int n; cin>>n; rep(i,n){ int t; cin>>t; a[i] = t; } vector> E(n); rep(i,n-1){ int a,b; cin>>a>>b; a--,b--; E[a].push_back(b); E[b].push_back(a); } dfs(0,-1,E); cout<