#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;} #define debug(x) cerr << #x << " = " << (x) << endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec<ll> A(N),B(N); for(auto& x:A) cin >> x; for(auto& x:B) cin >> x; vvec<int> g(N); for(int i=0;i<N-1;i++){ int a,b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } ll inf = 1e18; vvec<ll> dp(N,vec<ll>(2,0)); auto dfs = [&](auto&& self,int cur,int par)->void{ for(auto& to:g[cur]) if(to!=par){ self(self,to,cur); dp[cur][0] += max(dp[to][0],dp[to][1]); dp[cur][1] += max(dp[to][0],dp[to][1]+B[to]+B[cur]); } dp[cur][0] += A[cur]; }; dfs(dfs,0,-1); cout << max(dp[0][0],dp[0][1]) << "\n"; }