#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long t[200005];
int h[200005], deg[200005], in[200005], out[200005];
bool vis[200005];
long long dp[2][200005];
vector<int> adj[200005];
void dfs(int n, int par) {
  vis[n] = 1;
  vector<long long> val;
  int chi = 0;
  long long tot = 0;
  for (int v : adj[n]) {
    if (v != par) {
      chi++;
      dfs(v, n);
      val.push_back(dp[0][v] - dp[1][v]);
      tot += dp[1][v];
    }
  }
  sort(val.begin(), val.end());
  reverse(val.begin(), val.end());
  if (!par) {
    dp[0][n] = tot + t[n] * min(in[n], out[n] + chi);
  } else {
    dp[0][n] = tot + t[n] * min(in[n], out[n] + chi + 1);
    dp[1][n] = tot + t[n] * min(in[n] + 1, out[n] + chi);
  }
  for (int i = 0; i < val.size(); i++) {
    if (i) val[i] += val[i - 1];
    if (!par) {
      dp[0][n] =
          max(dp[0][n],
              val[i] + tot + t[n] * min(in[n] + i + 1, out[n] + (chi - i - 1)));
    } else {
      dp[0][n] = max(
          dp[0][n],
          val[i] + tot + t[n] * min(in[n] + i + 1, out[n] + 1 + (chi - i - 1)));
      dp[1][n] = max(
          dp[1][n],
          val[i] + tot + t[n] * min(in[n] + 1 + i + 1, out[n] + (chi - i - 1)));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i];
  for (int i = 1; i <= n; i++) cin >> h[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    deg[a]++, deg[b]++;
    if (h[a] == h[b]) {
      adj[a].push_back(b);
      adj[b].push_back(a);
    } else {
      if (h[a] < h[b])
        out[a]++, in[b]++;
      else
        in[a]++, out[b]++;
    }
  }
  for (int i = 1; i <= n; i++) ans += t[i] * deg[i];
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, 0);
      ans -= dp[0][i];
    }
  }
  cout << ans << "\n";
}
