#include #include using namespace std; #include using mint = atcoder::modint998244353; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; vector> to(N); for (int e = 1; e < N; ++e) { int a, b; cin >> a >> b; --a, --b; to.at(a).push_back(b); to.at(b).push_back(a); } vector A(N); for (auto &x : A) cin >> x; mint ret = 0; for (int d = 29; d >= 0; --d) { auto rec = [&](auto &&self, int now, int prv) -> pair { mint dp0(0), dp1(0); if (A.at(now) & (1 << d)) dp1 = 1; else dp0 = 1; for (int nxt : to.at(now)) { if (nxt == prv) continue; const auto [ch0, ch1] = self(self, nxt, now); mint dp0nxt = dp0 * (ch0 + ch1) + dp1 * ch1; mint dp1nxt = dp0 * ch1 + dp1 * (ch0 + ch1); dp0 = dp0nxt; dp1 = dp1nxt; } return {dp0, dp1}; }; ret = ret * 2 + rec(rec, 0, -1).second; } cout << ret.val() << '\n'; }