/** * @FileName a.cpp * @Author kanpurin * @Created 2020.09.05 03:09:52 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int n; vector> g; vector a,b; pair dfs(int v, int p = -1) { pair ret = {a[v],0}; for(int u : g[v]) { if (u == p) continue; auto t = dfs(u,v); ret.first += max(t.first,t.second); ret.second += max(b[u] + t.second + b[v], t.first); } return ret; } int main() { cin >> n; a.resize(n); b.resize(n); g.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n-1; i++) { int u,v;cin >> u >> v; u--;v--; g[u].push_back(v); g[v].push_back(u); } auto ans = dfs(0); cout << max(ans.first,ans.second) << endl; return 0; }