#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;
const Mint INV2 = Mint(2).inv();
struct Node {
int l, r;
Mint sum0, sum1, lz;
Node() : l(0), r(0), sum0(0), sum1(0), lz(1) {}
void mul(Mint val) {
sum0 *= val;
sum1 *= val;
lz *= val;
}
};
int V;
Node nodes[50'000'010];
void push(int u) {
Mint &lz = nodes[u].lz;
if (lz.x != 1) {
const int l = nodes[u].l;
const int r = nodes[u].r;
if (l) nodes[l].mul(lz);
if (r) nodes[r].mul(lz);
lz = 1;
}
}
void pull(int u) {
const int l = nodes[u].l;
const int r = nodes[u].r;
nodes[u].sum0 = nodes[l].sum0 + nodes[r].sum0;
nodes[u].sum1 = nodes[l].sum1 + nodes[r].sum1;
}
int merge(int u, int v, Mint sumU, Mint sumV, int L, int R) {
if (!u && !v) return 0;
if (!u) {
nodes[v].mul(sumU);
return v;
}
if (!v) {
nodes[u].mul(sumV);
return u;
}
assert(L != R-1);
const int Mid = (L + R) >> 1;
assert(nodes[u].l || nodes[u].r || nodes[v].l || nodes[v].r);
push(u);
push(v);
nodes[u].l = merge(nodes[u].l, nodes[v].l, nodes[nodes[u].r].sum0 + sumU, nodes[nodes[v].r].sum0 + sumV, L, Did);
nodes[u].r = merge(nodes[u].r, nodes[v].r, sumU, sumV, Mid, R);
pull(u);
return u;
}
int pointAdd(int u, int L, int R, int a, Mint val0, Mint val1) {
if (!u) {
u = V++;
nodes[u] = Node();
}
if (L + 1 == R) {
nodes[u].sum0 += val0;
nodes[u].sum1 += val1;
return u;
}
const int Mid = (L + R) >> 1;
push(u);
if (a < Mid) {
nodes[u].l = pointAdd(nodes[u].l, L, Mid, a, val0, val1);
} else {
nodes[u].r = pointAdd(nodes[u].r, Mid, R, a, val0, val1);
}
pull(u);
return u;
}
void debug(int u, int L, int R, bool pu) {
if (!u) return;
if (!pu) cerr << "[" << L << "," << R << "):" << (32 * nodes[u].sum0) << "," << (32 * nodes[u].sum1) << "," << (32 * nodes[u].lz) << " ";
if (L + 1 == R) {
if (pu) cerr << L << ":" << (32 * nodes[u].sum0) << "," << (32 * nodes[u].sum1) << " ";
return;
}
const int Mid = (L + R) >> 1;
if (pu) push(u);
debug(nodes[u].l, L, Mid, pu);
debug(nodes[u].r, Mid, R, pu);
}
int N;
vector<int> C;
vector<int> A, B;
vector<vector<int>> graph;
vector<pair<int, int>> cus;
Mint ans;
int dfs(int u, int p) {
const int pos = lower_bound(cus.begin(), cus.end(), make_pair(C[u], u)) - cus.begin();
int ret = pointAdd(0, 0, N, pos, 1, C[u]);
for (const int v : graph[u]) if (p != v) {
int res = dfs(v, u);
// connect
nodes[res].mul(INV2);
// cut
ans += nodes[res].sum1;
ret = merge(ret, res, 0, INV2);
}
// cerr<<"u = "<<u<<": ";debug(ret,0,N,false);cerr<<endl;
// cerr<<"u = "<<u<<": ";debug(ret,0,N,true);cerr<<endl;
return ret;
}
int main() {
for (; ~scanf("%d", &N); ) {
C.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &C[u]);
}
A.resize(N - 1);
B.resize(N - 1);
for (int i = 0; i < N - 1; ++i) {
scanf("%d%d", &A[i], &B[i]);
--A[i];
--B[i];
}
graph.assign(N, {});
for (int i = 0; i < N - 1; ++i) {
graph[A[i]].push_back(B[i]);
graph[B[i]].push_back(A[i]);
}
cus.resize(N);
for (int u = 0; u < N; ++u) {
cus[u] = make_pair(C[u], u);
}
sort(cus.begin(), cus.end());
// cerr<<"cus = "<<cus<<endl;
ans = 0;
V = 1;
const int res = dfs(0, -1);
ans += nodes[res].sum1;
ans *= Mint(2).pow(N - 1);
printf("%u\n", ans.x);
}
return 0;
}