#include <bits/stdc++.h>
using namespace std;
template <typename input_type>
input_type input() {
  input_type inp;
  cin >> inp;
  return inp;
}
const int max_sz = 2e5 + 5, useless = 2;
bool mark[max_sz];
int sz;
long long ans, dp[max_sz][useless];
pair<int, int> info[max_sz], dgr[max_sz];
vector<int> graph[max_sz];
inline bool CMP(int vrtx1, int vrtx2) {
  return ((dp[vrtx1][0] - dp[vrtx1][1]) > (dp[vrtx2][0] - dp[vrtx2][1]));
}
void DFS(int vrtx, int par) {
  vector<int> child;
  long long int sum = 0;
  mark[vrtx] = true;
  for (auto ngh : graph[vrtx]) {
    if (not mark[ngh]) {
      DFS(ngh, vrtx);
      child.push_back(ngh);
      sum += dp[ngh][1];
    }
  }
  sort(child.begin(), child.end(), CMP);
  if (par != vrtx) {
    dp[vrtx][0] = max(dp[vrtx][0],
                      ((long long)min(dgr[vrtx].first + ((int)child.size() + 1),
                                      dgr[vrtx].second) *
                       info[vrtx].second) +
                          sum);
    dp[vrtx][1] =
        max(dp[vrtx][1], ((long long)min(dgr[vrtx].first + (int)child.size(),
                                         dgr[vrtx].second + 1) *
                          info[vrtx].second) +
                             sum);
  } else {
    dp[vrtx][0] = max(
        dp[vrtx][0],
        ((long long)min(dgr[vrtx].first + (int)child.size(), dgr[vrtx].second) *
         info[vrtx].second) +
            sum);
  }
  for (int i = 0; i < child.size(); i++) {
    sum += dp[child[i]][0] - dp[child[i]][1];
    if (par != vrtx) {
      dp[vrtx][0] =
          max(dp[vrtx][0],
              ((long long)min(dgr[vrtx].first + ((int)child.size() - i),
                              dgr[vrtx].second + (i + 1)) *
               info[vrtx].second) +
                  sum);
      dp[vrtx][1] =
          max(dp[vrtx][1],
              ((long long)min(dgr[vrtx].first + ((int)child.size() - (i + 1)),
                              dgr[vrtx].second + (i + 2)) *
               info[vrtx].second) +
                  sum);
    } else {
      dp[vrtx][0] =
          max(dp[vrtx][0],
              ((long long)min(dgr[vrtx].first + ((int)child.size() - (i + 1)),
                              dgr[vrtx].second + (i + 1)) *
               info[vrtx].second) +
                  sum);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  sz = input<int>();
  for (int i = 0; i < sz; i++) {
    info[i].second = input<int>();
  }
  for (int i = 0; i < sz; i++) {
    info[i].first = input<int>();
  }
  for (int i = 0; i < (sz - 1); i++) {
    pair<int, int> endpnt = {input<int>() - 1, input<int>() - 1};
    ans += info[endpnt.first].second + info[endpnt.second].second;
    if (info[endpnt.first].first == info[endpnt.second].first) {
      graph[endpnt.first].push_back(endpnt.second);
      graph[endpnt.second].push_back(endpnt.first);
    } else {
      if (info[endpnt.first].first > info[endpnt.second].first) {
        swap(endpnt.first, endpnt.second);
      }
      dgr[endpnt.first].first++;
      dgr[endpnt.second].second++;
    }
  }
  for (int i = 0; i < sz; i++) {
    if (not mark[i]) {
      DFS(i, i);
      ans -= dp[i][0];
    }
  }
  cout << ans;
  return 0;
}
