n=int(input()) a=list(map(int,input().split())) e=[[] for i in range(n)] for i in range(n-1): u,v=map(int,input().split()) u-=1 v-=1 e[u]+=[v] e[v]+=[u] M=998244353 i2=pow(2,M-2,M) u=[0]*n v=[0]*n q=[0] ans=0 while len(q)>0: s=q[-1] if v[s]==0: v[s]=1 for t in e[s]: if v[t]==0: q+=[t] else: f=0 for t in e[s]: if v[t]==0: f=1 u[s]+=u[t]*a[s] u[s]%=M u[s]+=a[s] u[s]%=M ans+=u[s] ans%=M a2=0 for t in e[s]: if v[t]==0: a2+=u[t] a2%=M a2=a2**2 for t in e[s]: if v[t]==0: a2-=u[t]**2 a2%=M a2*=i2 a2%=M ans+=a2*a[s] ans%=M v[s]=0 q.pop() ans-=sum(a) ans%=M print(ans)