#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n), b(n); for(int i = 0; i < n; ++i) cin >> a[i]; for(int i = 0; i < n; ++i) cin >> b[i]; vector> graph(n); for(int i = 1; i < n; ++i){ int u, v; cin >> u >> v; --u, --v; graph[u].emplace_back(v); graph[v].emplace_back(u); } constexpr ll inf = 1e+17; vector> dp(n, vector(2, -inf)); auto func = [&](auto&& self, int v = 0, int i = 0, int par = -1) -> ll { if(dp[v][i] != -inf) return dp[v][i]; ll res = 0; if(i == 0){ res = a[v]; for(int child : graph[v]){ if(child == par) continue; res += max(self(self, child, 0, v), self(self, child, 1, v)); } } else{ for(int child : graph[v]){ if(child == par) continue; res += max(self(self, child, 0, v), self(self, child, 1, v) + b[v] + b[child]); } } return dp[v][i] = res; }; cout << max(func(func), func(func, 0, 1)) << endl; return 0; }