#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
vector<vector<int> > g;
vector<ll> c;
vector<ll> sub;
int n;
pair<ll,ll> dfs(int id,int pre){
    ll mi = 0;
    ll sm = 0;
    map<int,ll> mp;
    for(auto x:g[id]){
        if(x!=pre){
            auto y = dfs(x,id);
            chmin(mi,y.first);
            sm += y.second;
            sub[id] += sub[x];
        }
    }
    sub[id]++;
    sm += -mi;
    ll cc = -mi;
    c[id] -= (ll)cc*(ll)g[id].size();
    if(pre!=-1){
        c[pre] += cc;
    }
    for(auto x:g[id]){
        if(x!=pre){
            c[x] += cc;
        }
    }
    for(auto x:g[id]){
        if(x!=pre){
            if(c[x]>0){
                sm += c[x]*sub[x];
                c[id] += c[x];
                c[x] = 0;
            }
        }
    }
    if(c[id]>0){
        sm += sub[id]*c[id];
        c[pre] += c[id];
        c[id] = 0;
    }
    return MP(c[id],sm);
}

int main(){

    cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    sub.resize(n);
    g.resize(n);
    c.resize(n);
    rep(i,n-1){
        int s,t;
        cin >> s >> t;
        s--;t--;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n)c[i] = a[i]-b[i];
    auto x = dfs(0,-1);
    cout << x.second << endl;
    return 0;
}
