#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

int n;
vvector<int> edges;
vector<ll> willout;
vector<int> parent;
int root;


void setup(){
  n = in();
  edges.resize(n);
  willout.resize(n);
  rep(i,n-1){
    int a = in() - 1;
    int b = in() - 1;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  foreach(i,willout)i=in();
  foreach(i,willout)i-=in();
  root = max_element(all(willout)) - willout.begin();
  stack<int> st;
  vvector<int> true_edges(n);
  vector<int> used(n,false);
  used[root] = true;
  st.push(root);
  parent.resize(n,-1);
  while(st.size()){
    int d = st.top();
    st.pop();
    foreach(i,edges[d]){
      if(used[i])continue;
      used[i]=true;
      true_edges[d].push_back(i);
      parent[i] = d;
      st.push(i);
    }
  }
  edges = true_edges;
}

int child_num(int place){
  static vector<int> memo(n,-1);
  int &it = memo[place];
  if(it>=0)return it;
  it = 0;
  foreach(i,edges[place]){
    it += 1 + child_num(i);
  }
  return it;
}

ll func(int place){
  ll res = 0;
  foreach(i,edges[place])res+=func(i);
  vector<pll> line;
  foreach(i,edges[place]){
    line.emplace_back(willout[i],i);
  }
  sort(all(line),[](pll a,pll b){return a.first>b.first;});
  ll outed = 0;
  ll dirs = (parent[place]>=0)+edges[place].size();
  ll child_sum = 0;
  foreach(i,line){
    ll dis = outed - i.first;
    outed = i.first;
    res += (child_sum+1) * dis;
    willout[place] -= dirs * dis;
    if(parent[place]>=0)willout[parent[place]]+=dis;
    --dirs;
    child_sum += child_num(i.second)+1;
  }
  if(willout[place]>0){
    res += willout[place] * (child_num(place)+1);
    willout[parent[place]] += willout[place];
    willout[place] = 0;
  }
  return res;
}

int main(){
  setup();
  cout << func(root) << endl;
  return 0;
}

