#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } constexpr ll mod = 998244353; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector> g(n); for (int i = 0; i < n - 1; ++i) { int x,y; cin >> x >> y; x--; y--; g[x].push_back(y); g[y].push_back(x); } vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } ll res = 0; for (int i = 0; i < 30; ++i) { vector> dp(2, vector(n)); auto dfs = [&](auto dfs, int s, int p) -> void { vector d(2); d[0] = 1; for (int t : g[s]) { if (t == p) continue; dfs(dfs, t, s); ll d0 = d[0], d1 = d[1]; d[0] = (d0*dp[0][t] + d1*dp[1][t] + d0*dp[1][t]) % mod; d[1] = (d1*dp[0][t] + d0*dp[1][t] + d1*dp[1][t]) % mod; } int u = 0; if ((1<