# 全方位木DP from collections import deque import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) mod = 998244353 X = [[] for i in range(N)] for i in range(N - 1): x, y = map(int, input().split()) X[x - 1].append(y - 1) X[y - 1].append(x - 1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) # Settings unit = 0 def merge(a, b): return (a + b) % mod def adj_bu(a, i): return (a + 1) * A[i] % mod def adj_td(a, i, p): return (a + 1) * A[p] % mod def adj_fin(a, i): return (a + 1) * A[i] % mod ##### ME = [unit] * N XX = [0] * N TD = [unit] * N for i in R[1:][::-1]: XX[i] = adj_bu(ME[i], i) p = P[i] ME[p] = merge(ME[p], XX[i]) XX[R[0]] = adj_fin(ME[R[0]], R[0]) # print("ME =", ME) # Merge before adj # print("XX =", XX) # Bottom-up after adj for i in R: ac = TD[i] for j in X[i]: TD[j] = ac ac = merge(ac, XX[j]) ac = unit for j in X[i][::-1]: TD[j] = adj_td(merge(TD[j], ac), j, i) ac = merge(ac, XX[j]) XX[j] = adj_fin(merge(ME[j], TD[j]), j) # print("TD =", TD) # Top-down after adj # print("XX =", XX) # Final Result s = 0 for x in XX: s += x s %= mod s -= sum(A) s *= pow(2, mod - 2, mod) s %= mod print(s)