老是看错题。。。。
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
using ll=long long;
ll n,c[209],a[209],ss,tt,ans;
int hd[(int)1e5+9],cur[(int)1e5+9],tot=1,dep[(int)1e5+9];
struct Edge{
int to,nxt,v;
}e[(int)5e5+9];
void add(int u,int v,int w){
e[++tot]={v,hd[u],w},hd[u]=tot;
e[++tot]={u,hd[v],0ll},hd[v]=tot;
}
vi g[209],dis[209][209];
bitset<209> vis;
void ddfs(int u,int d,int rt){
vis[u]=1,dis[rt][d].push_back(u);
for(auto it:g[u]){
if(!vis[it])ddfs(it,d+1,rt);
}
}
bool bfs(int st,int en){
for(int i=0;i<=tt;++i)dep[i]=0;
queue<int>q;
memcpy(cur,hd,sizeof(hd));
q.push(st);
dep[st]=1;
while(!q.empty()){
auto u=q.front();
q.pop();
for(int eg=hd[u];eg;eg=e[eg].nxt){
if(!dep[e[eg].to]&&e[eg].v>0){
dep[e[eg].to]=dep[u]+1;
q.push(e[eg].to);
}
}
}
return !!dep[en];
}
int dfs(int u,int en,int flow){
if(u==en)return flow;
int r=flow;
for(int eg=cur[u];eg&&r;eg=e[eg].nxt){
cur[u]=eg;
if(e[eg].v>0&&dep[e[eg].to]==dep[u]+1){
int c=dfs(e[eg].to,en,min(r,e[eg].v));
r-=c;
e[eg].v-=c,e[eg^1].v+=c;
}
}
return flow-r;
}
int dinic(int st,int en){
int ret=0;
while(bfs(st,en)){
ret+=dfs(st,en,0x3f3f3f3f);
}
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
ss=n*n+n+1,tt=ss+1;
for(int i=1;i<=n;++i){
cin>>c[i];
add(i+n*n,tt,c[i]);
}
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1,x,y;i<n;++i){
cin>>x>>y;
g[x].push_back(y),g[y].push_back(x);
}
for(int i=1;i<=n;++i){
vis.reset();
ddfs(i,0,i);
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
add(ss,(i-1)*n+j,a[j]-a[j-1]);
if(j>1)add((i-1)*n+j,(i-1)*n+j-1,0x3f3f3f3f);
for(auto it:dis[i][j-1])add((i-1)*n+j,n*n+it,0x3f3f3f3f);
}
}
ans=n*a[n]-dinic(ss,tt);
cout<<ans;
return 0;
}