namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { const int Mod = 998244353; const int Half = (Mod + 1) / 2; object? Solve() { var n = Int(); var az = n.Repeat(Input); var g = n.Repeat(() => new List()); for (var i = 0; i < n - 1; i++) { var u = Int() - 1; var v = Int() - 1; g[u].Add(v); g[v].Add(u); } (long, long) F(int v, int last) { var a = az[v]; var r1 = 0L; var r2 = a; var r1p = 0L; var r1d = 0L; foreach (var u in g[v]) if (u != last) { var (n1, n2) = F(u, v); r1 = (r1 + n1 + n2) % Mod; r2 = (r2 + n2 * a) % Mod; r1p += n2; r1d = (r1d + n2 * n2) % Mod; } r1p %= Mod; r1p = r1p * r1p % Mod; var r1t = (r1p - r1d + Mod) % Mod * Half % Mod * a % Mod; r1 = (r1 + r1t) % Mod;; return (r1, r2); } var ans = F(0, -1); return (ans.Item1 + ans.Item2 + Mod - az.Sum() % Mod) % Mod; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } }