#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair; template ostream& operator<<(ostream& os, pair a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template ostream& operator<<(ostream& os, vector v) { for (auto x : v) os << x << ' '; return os; } void debug() { cerr << '\n'; } template void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } ll dp[2][100005]; vectorg[100005]; ll a[100005]; ll b[100005]; void dfs(int s, int p){ for(int x: g[s]){ if(x == p)continue; dfs(x, s); dp[0][s] += max(dp[0][x], dp[1][x]); dp[1][s] += max(dp[0][x], dp[1][x] + b[s] + b[x]); } dp[0][s] += a[s]; } int main(){ cin.tie(nullptr); 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].push_back(v); g[v].push_back(u); } dfs(0, -1); cout << max(dp[0][0], dp[1][0]) << endl; }