import sys sys.setrecursionlimit(2*10**5) N=int(input()) dp1=[0]+list(map(int,input().split())) dp2=[0]*(N+1) # remain b=[0]+list(map(int,input().split())) g=[[] for _ in range(N+1)] for _ in range(N-1): u,v=map(int,input().split()) g[u].append(v) g[v].append(u) def dfs(v,p): for u in g[v]: if u!=p: continue dfs(u,v) dp1[v]+=max(dp1[u],dp2[u]) dp2[v]+=max(dp1[u],dp2[u]+b[u]+b[v]) dfs(1,0) print(max(dp1[1],dp2[1]))