#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

int N;
int A[100010], B[100010], C[100010];
int cnt[100010];
const int MAX_V = 100010;
const int MAX_LOG_V = 20;
vector<int> G[MAX_V];
int root;//根の番号

int parent[MAX_LOG_V][MAX_V];//親を2^k回辿って到達する頂点
int depth[MAX_V];
vector<int>d_nodes[100010];

void dfs(int v, int p, int d) {
	parent[0][v] = p;
	depth[v] = d;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i] != p)dfs(G[v][i], v, d + 1);
	}
}

void init(int V) {
	dfs(root, -1, 0);
	for (int k = 0; k + 1 < MAX_LOG_V; k++) {
		for (int v = 0; v < V; v++) {
			if (parent[k][v] < 0)parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) {
		swap(u, v);
	}
	for (int k = 0; k < MAX_LOG_V; k++) {
		if ((depth[v] - depth[u]) >> k & 1) {
			v = parent[k][v];
		}
	}
	if (u == v)return u;
	for (int k = MAX_LOG_V - 1; k >= 0; k--) {
		if (parent[k][u] != parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}

int add_cnt[100010];

void calc_cnt(int n, int par,int res) {
	cnt[n] += add_cnt[n]+res;
	for (auto nxt : G[n]) {
		if (nxt == par)continue;
		calc_cnt(nxt, n, res + add_cnt[n]);
	}
}

void solve() {
	cin >> N;
	REP(i, N - 1) {
		int u, v; cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);

	}
	root = 0;
	init(N);
	REP(i, N)cin >> A[i];
	REP(i, N)cin >> B[i];
	REP(i, N)C[i] = A[i] - B[i];
	int MAX_DEPTH = 0;
	REP(i, N) {
		chmax(MAX_DEPTH, depth[i]);
		d_nodes[depth[i]].push_back(i);
	}
	REPR(d, MAX_DEPTH + 1) {
		if (d == 0)break;
		int idx = 0, mn = 1e18;
		vector<P>vs;
		//cout << "depth:" << d << endl;
		for (int v : d_nodes[d]) {
			vs.push_back({ C[v],v });
		}
		VSORT(vs);
		for (auto p : vs) {
			int v = p.second;
			//pe(v+1); print(C[v]);
			if (C[v] < 0) {
				int par = parent[0][v];
				int c = -C[v];
				cnt[par] += c;
				int cntchi = 0;
				for (auto chi : G[par]) {
					//if (chi == parent[0][par])continue;
					C[chi] += c;
					cntchi++;
				}
				C[par] -= c * G[par].size();
			}
			else {
				int par = parent[0][v];
				add_cnt[v] += C[v];
				C[par] += C[v];
			}
		}
	}
	calc_cnt(0, 0, 0);
	//REP(i, N) {
	//	pe(cnt[i]);
	//}cout << endl;
	int mn = 1e9;
	REP(i, N)chmin(mn, cnt[i]);
	int sum = 0;
	REP(i, N) {
		sum += cnt[i];
	}
	print(sum - mn * N);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 37528