#include <bits/stdc++.h>
int read() {
  static int c, x;
  while ((c = getchar()) < 48) {
  }
  x = c & 15;
  while ((c = getchar()) >= 48) x = x * 10 + (c & 15);
  return x;
}
struct edge {
  int next, to;
} e[200010 << 1];
int head[200010], val[200010], a[200010];
long long dp0[200010], dp1[200010], tp[200010];
inline void add(const int &x, const int &y) {
  static int ei;
  e[++ei].next = head[x];
  e[ei].to = y;
  head[x] = ei;
}
void dfs(const int &f, const int &fa) {
  int cnt = 0, ca = 0, cb = 0;
  long long sum = 0;
  for (int i = head[f]; i; i = e[i].next) {
    const int t = e[i].to;
    if (t != fa) {
      dfs(t, f);
      if (a[f] >= a[t]) {
        sum += dp0[t];
        ++ca;
      } else {
        sum += dp1[t];
        ++cb;
      }
    }
  }
  for (int i = head[f]; i; i = e[i].next) {
    const int t = e[i].to;
    if (t != fa && a[f] == a[t]) {
      tp[++cnt] = dp1[t] - dp0[t];
    }
  }
  std::sort(tp + 1, tp + cnt + 1);
  dp0[f] = sum + 1ll * std::max(ca, cb + (f != 1)) * val[f];
  dp1[f] = sum + 1ll * std::max(ca + (f != 1), cb) * val[f];
  for (int i = 1; i <= cnt; ++i) {
    --ca;
    ++cb;
    sum += tp[i];
    dp0[f] = std::min(dp0[f], sum + 1ll * std::max(ca, cb + (f != 1)) * val[f]);
    dp1[f] = std::min(dp1[f], sum + 1ll * std::max(ca + (f != 1), cb) * val[f]);
  }
}
int main() {
  const int n = read();
  for (int i = 1; i <= n; ++i) val[i] = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = n; --i;) {
    const int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  printf("%lld\n", dp0[1]);
  return 0;
}
