#include template struct y_combinator : private F { y_combinator(F f) : F(f) {} template decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; int main() { using namespace std; cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector a(n), b(n); for (auto&& e : a) cin >> e; for (auto&& e : b) cin >> e; vector> g(n); for (int _ = n - 1; _--;) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } // vertex v -> -a[v] // edge uv -> b[u] + b[v] vector> dp(n); y_combinator([&](auto&& self, int v, int p) -> void { dp[v] = {a[v], 0}; for (int u : g[v]) { if (u == p) continue; self(u, v); array new_dp; new_dp.fill(-1e18); for (int x : {0, 1}) for (int y : {0, 1}) new_dp[x] = max(new_dp[x], dp[v][x] + dp[u][y] + x * y * (b[v] + b[u])); swap(dp[v], new_dp); } })(0, -1); cout << max(dp[0][0], dp[0][1]) << '\n'; }