#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 //#define MOD 1000000007 #define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 const double EPS = 1e-10; using ll = long long; using Pi = pair; using Pl = pair; int n; vector a,b; vector> G; ll dp[100010][2]; ll dfs(int u, int k, int p){ if(p != -1 && G[u].size() == 1){ if(k == 0) return a[u]; else return 0; } if(dp[u][k] != -LINF) return dp[u][k]; ll res = 0; if(k == 0) res = a[u]; for(int v : G[u]){ if(v == p) continue; if(k == 0){ res += max(dfs(v,0,u),dfs(v,1,u)); } else res += max(dfs(v,0,u),dfs(v,1,u)+b[u]+b[v]); } return dp[u][k] = res; } int main(){ cin >> n; a.resize(n); b.resize(n); G.resize(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].push_back(v); G[v].push_back(u); } rep(i,100010)rep(j,2) dp[i][j] = -LINF; cout << max(dfs(0,0,-1),dfs(0,1,-1)) << endl; }