#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
ll A[100010],B[100010];
vector<ll> g[100010];
vector<ll> ds[100010];
ll C[100010];

ll predfs(ll v,ll pre){
	ll sum=0;
	rep(i,g[v].size()){
		ll nv=g[v][i];
		if(nv==pre){
			ds[v].push_back(-1);
			continue;
		}
		ll t=predfs(nv,v);
		ds[v].push_back(t);
		sum+=t;
	}

	return (A[v]-B[v]+sum);
}

void dfs(ll v,ll pre,ll s){
	C[v]=s;
	rep(i,g[v].size()){
		if(g[v][i]==pre){
			continue;
		}
		dfs(g[v][i],v,s+ds[v][i]);
	}
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N;
  rep(i,N-1){
  	ll a,b;
  	cin>>a>>b;
  	a--;b--;
  	g[a].push_back(b);
  	g[b].push_back(a);
  }
  rep(i,N){
  	cin>>A[i];
  }
  rep(i,N)cin>>B[i];
  predfs(0,-1);
  dfs(0,-1,0);
  ll mn=0;
  rep(i,N){
  	minch(mn,C[i]);
  }
  ll res=0;
  rep(i,N){
  	res+=C[i]-mn;
  }
  cout<<res<<endl;

  return 0;
}

