#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int n; vector tree[100005]; ll a[100005]; ll b[100005]; ll dp[100005][2]; pll dfs(int i,int before){ ll one = a[i]; ll two = 0; for(int j:tree[i]){ if(j==before) continue; pll now = dfs(j,i); one += max(now.first,now.second); two += max(now.first,now.second+b[j]+b[i]); } dp[i][0] = one; dp[i][1] = two; return pll(one,two); } int main(){ 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; tree[u].push_back(v); tree[v].push_back(u); } dfs(0,-1); cout << max(dp[0][0],dp[0][1]) << endl; return 0; }