using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var map = NMap(n - 1); var tree = new List[n]; for (var i = 0; i < n; ++i) tree[i] = new List(); foreach (var edge in map) { tree[edge[0]].Add(new Pair(edge[1])); tree[edge[1]].Add(new Pair(edge[0])); } DFS1(0, -1, a, tree); var ans = new long[n]; DFS2(0, -1, 0, a, tree, ans); var d = 0L; for (var i = 0; i < n; ++i) d = (d + ans[i] - a[i] + mod) % mod; WriteLine(d * 499_122_177 % mod); } class Pair { public int To; public long Num; public Pair(int to) { To = to; } } static int mod = 998_244_353; static long DFS1(int cur, int prev, int[] a, List[] tree) { var sum = (long)a[cur]; foreach (var next in tree[cur]) { if (next.To == prev) continue; var sub = DFS1(next.To, cur, a, tree); next.Num = sub * a[cur] % mod; sum = (sum + next.Num) % mod; } return sum; } static void DFS2(int cur, int prev, long val, int[] a, List[] tree, long[] ans) { var sum = (val * a[cur] + a[cur]) % mod; foreach (var next in tree[cur]) { if (next.To == prev) continue; sum = (sum + next.Num) % mod; } ans[cur] = sum; foreach (var next in tree[cur]) { if (next.To == prev) continue; DFS2(next.To, cur, (sum - next.Num + mod) % mod, a, tree, ans); } } }