#include #include #include #include #include #include #include using namespace std; typedef long long ll; int N; ll a[100000]; ll b[100000]; bool used[100000]; vector G[100000]; // dp1残す、dp2残さない ll dp1[100000], dp2[100000]; const ll INF = 1e18; void dfs(int v){ used[v] = true; dp2[v] = a[v]; ll max1 = -INF, max2 = -INF; for(int to : G[v]){ if(!used[to]){ dfs(to); dp1[v] += max(dp1[to]+b[to]+b[v], dp2[to]); dp2[v] += max(dp1[to], dp2[to]); } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> 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); } dfs(0); cout << max(dp1[0], dp2[0]) << endl; }