#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   const int maxn = (int)2e5 + 10;   vector<int> ed[maxn];   int t[maxn], h[maxn];   long long dp[maxn][2];   void go(int v, int p) {     vector<pair<long long, int> > g;     int in = 0;     int out = 0;     long long sc = 0;     for (int u : ed[v]) {       if (u == p) {         continue;       }       go(u, v);       if (h[u] > h[v]) {         out++;         sc += dp[u][0];       } else if (h[u] < h[v]) {         in++;         sc += dp[u][1];       } else {         out++;         g.push_back(make_pair(-dp[u][0] + dp[u][1], u));         sc += dp[u][0];       }     }     sort((g).begin(), (g).end());     for (int it = 0; it < 2; it++) {       if (p != -1)         if (it == 0) {           in++;         } else {           out++;         }       long long ans = (long long)1e18;       long long cur = sc;       for (int i = 0; i <= (int)g.size(); i++) {         ans = min(ans, cur + max(in + i, out - i) * (long long)t[v]);         if (i != (int)g.size()) cur += g[i].first;       }       dp[v][it] = ans;       if (p != -1)         if (it == 0) {           in--;         } else {           out--;         }     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &t[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &h[i]);     }     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       ed[x].push_back(y);       ed[y].push_back(x);     }     go(0, -1);     cout << dp[0][0] <<   n ;   }   