#include #define endl "\n" using namespace std; #define ll long long #define ld long double #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repo(i,n) for(int i = 1; i < (int)(n); i++) #define pb push_back #define mp make_pair #define np next_permutation #define fi first #define se second #define all(x) (x).begin(),(x).end() #define uniq(v) v.erase(unique(v.begin(),v.end()),v.end()) #define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin()) #define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin()) using Pair = pair>; #define pq priority_queue, greater> const ll mod=1000000007; //const ll mod=998244353; const ld pi=acos(-1.0); const ll INF = 1LL<<61; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b dp0(MAX, 0), dp1(MAX, 0), a(MAX), b(MAX); vector> g(MAX); void dfs(int i, int p) { dp0[i] += a[i]; for (int j : g[i]) { if (j == p) continue; dfs(j, i); dp0[i] += max(dp0[j], dp1[j]); dp1[i] += max(dp0[j], dp1[j] + b[i] + b[j]); } return; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; rep(i,n-1){ int u, v; cin >> u >> v; u--; v--; g[u].pb(v); g[v].pb(u); } dfs(0, -1); cout << max(dp0[0], dp1[0]) << endl; }