#include #include using namespace std; #include using mint = atcoder::modint998244353; int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; cin >> N; vector A(N); for (auto &a : A) cin >> a; vector> to(N); for (int e = 0; e < N - 1; ++e) { int u, v; cin >> u >> v; --u, --v; to.at(u).push_back(v); to.at(v).push_back(u); } mint ret = 0; auto rec = [&](auto &&self, int now, int prv) -> mint { mint w = A.at(now); for (int nxt : to.at(now)) { if (nxt == prv) continue; mint v = self(self, nxt, now); ret += v * w; w += v * A.at(now); } return w; }; rec(rec, 0, -1); cout << ret.val() << '\n'; }