N = gets.to_i A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) G = Array.new(N + 1){ [] } def max(a,b); a > b ? a : b; end class << G def bfs_order stack = [1] used = Array.new(size) order = [] until stack.empty? u = stack.pop next if used[u] used[u] = order.size order << u self[u].each do |v| next if used[v] stack << v end end order.reverse end end (1 ... N).each do a,b = gets.split.map(&:to_i) G[a] << b G[b] << a end order = G.bfs_order dp0 = Array.new(N + 1) dp1 = Array.new(N + 1) used = Array.new(N + 1) order.each do |u| used[u] = true dp0[u] = G[u].map do |v| next 0 if !used[v] max(dp0[v], dp1[v]) end.sum + A[u - 1] dp1[u] = G[u].map do |v| next 0 if !used[v] max(dp1[v] + B[v - 1] + B[u - 1], dp0[v]) end.sum end puts max(dp0[1], dp1[1])