#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


signed main(){
    int n;
    cin >> n;
    vector<int> u(n - 1), v(n - 1);
    vector<vector<int>> edges(n);
    for(int i = 0; i < n - 1; ++i){
        cin >> u[i] >> v[i];
        --u[i], --v[i];
        edges[u[i]].push_back(v[i]);
        edges[v[i]].push_back(u[i]);
    }
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < n; ++i)
        cin >> b[i];
    vector<int> diff(n);
    for(int i = 0; i < n; ++i)
        diff[i] = b[i] - a[i];

    vector<int> siz(n, -MOD);
    siz[0] = diff[0];
    vector<tuple<int, int, int>> diff_edges;
    function<void(int)> f = [&](int x){
        for(auto y : edges[x]){
            if(siz[y] == -MOD){
                siz[y] = diff[y];
                f(y);
                // x側からy側にsiz[y]だけ送りたい
                diff_edges.emplace_back(x, y, siz[y]);
                siz[x] += siz[y];
            }
        }
    };
    f(0);

    // 逆辺
    vector<vector<pair<i64, i64>>> sc_edges(n);
    for(int i = 0; i < n - 1; ++i){
        sc_edges[get<0>(diff_edges[i])].emplace_back(get<1>(diff_edges[i]), get<2>(diff_edges[i]));
        sc_edges[get<1>(diff_edges[i])].emplace_back(get<0>(diff_edges[i]), -get<2>(diff_edges[i]));
    }
    vector<i64> val(n, -INF);
    function<void(int)> g = [&](int x){
        for(auto& ed : sc_edges[x]){
            i64 y, dist;
            tie(y, dist) = ed;
            if(val[y] == -INF){
                val[y] = val[x] - dist;
                g(y);
            }
        }
    };
    val[0] = 0;
    g(0);
    i64 min_elm = *min_element(val.begin(), val.end());

    for(int i = 0; i < n; ++i)
        val[i] -= min_elm;

    i64 ans = 0;
    for(int i = 0; i < n; ++i)
        ans += val[i];
    cout << ans << endl;

}

