#include using namespace std; #define rep(i, n) for (int i=0; i G[100010]; int memo[2][100010]; int dfs(int v, int pv, int f) {//f:0 vを消す, f:1 vを消さない if (memo[f][v]!=-1) return memo[f][v]; int res = f==0 ? a[v]:0; if (f==0) { for (auto& nv:G[v]) { if (nv==pv) continue; res += max(dfs(nv, v, 0), dfs(nv, v, 1)); } } else { for (auto& nv:G[v]) { if (nv==pv) continue; res += max(dfs(nv, v, 0), dfs(nv, v, 1)+b[v]+b[nv]); } } return memo[f][v] = res; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; rep(i, N) cin >> a[i]; rep(i, N) cin >> b[i]; rep(i, N-1) { int u, v; cin >> u >> v; G[u-1].pb(v-1); G[v-1].pb(u-1); } rep(i, 2) rep(j, N) memo[i][j] = -1; cout << max(dfs(0, -1, 0), dfs(0, -1, 1)) << endl; }