#include const int maxn = 2e5 + 3; using ll = long long; int n, a[maxn], b[maxn], p[maxn]; std::vector E[maxn], c[maxn]; ll dp[maxn][2][2]; void dfs(int u) { for(auto &&v : E[u]) { if(v == p[u]) continue; p[v] = u; dfs(v); c[u].push_back(v); } ll au = a[u], bu = b[u]; { { ll &ansP = dp[u][1][1], &ansN = dp[u][1][0], dps = 0; std::vector tr; for(auto &&v : c[u]) { dps += dp[v][0][1]; tr.push_back(dp[v][1][1] - dp[v][0][1]); } std::sort(tr.rbegin(), tr.rend()); ll dpp = 0; ansP = dps + dpp + bu * 1ll; ansN = dps + dpp + bu * 0ll; for(int j = 0; j < c[u].size(); ++j) { dpp += tr[j]; ansP = std::max(ansP, dps + dpp + bu * ll(j + 2ll)); ansN = std::max(ansN, dps + dpp + bu * ll(j + 1ll)); } } { ll &ansP = dp[u][0][1], &ansN = dp[u][0][0], dps = 0; std::vector tr; for(auto &&v : c[u]) { dps += dp[v][0][0]; tr.push_back(dp[v][1][0] - dp[v][0][0]); } std::sort(tr.rbegin(), tr.rend()); ll dpp = 0; ansP = dps + dpp + au; ansN = dps + dpp + au; for(int j = 0; j < c[u].size(); ++j) { dpp += tr[j]; ansP = std::max(ansP, dps + dpp + au); ansN = std::max(ansN, dps + dpp + au); } } } } int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", a + i); for(int i = 1; i <= n; ++i) scanf("%d", b + i); for(int i = 0; i < n - 1; ++i) { int u, v; scanf("%d%d", &u, &v); E[u].push_back(v); E[v].push_back(u); } dfs(1); ll ans = dp[1][0][0]; for(int i = 0; i < 2; ++i) ans = std::max(ans, dp[1][i][0]); printf("%lld\n", ans); return 0; }