#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; #define PI 3.141592653589793 vector to[101010]; ll dp[101010][2]; ll c[101010], b[101010]; void DFS(int a, int p){ vector> kurabe; dp[a][0] = c[a]; for(auto k: to[a]){ if(k==p) continue; DFS(k, a); kurabe.push_back({dp[k][1]+b[a]+b[k]-dp[k][0], k}); if(dp[k][1]>dp[k][0]) dp[a][0]+=dp[k][1]; else dp[a][0]+=dp[k][0]; dp[a][1]+=dp[k][0]; } sort(kurabe.begin(), kurabe.end(), greater<>()); ll nyan = dp[a][1]; rep(i, kurabe.size()){ if(kurabe[i].first>0) dp[a][1]+=kurabe[i].first; } } int main(){ int n; cin >> n; rep(i, n) cin >> c[i]; rep(i, n) cin >> b[i]; rep(i, n-1){ int u, v; cin >> u >> v; u--; v--; to[u].push_back(v); to[v].push_back(u); } DFS(0, -1); cout << max(dp[0][0], dp[0][1]) << endl; //cout << dp[0][1] << endl; }