const INF: isize = 1isize << 60; fn dfs(cur: usize, prev: usize, a: &Vec, b: &Vec, paths: &Vec>, dp: &mut Vec>) { let mut unused = 0isize; let mut used = 0isize; for &v in paths[cur].iter() { if prev == v { continue; } dfs(v, cur, a, b, paths, dp); unused += dp[v][0].max(dp[v][1]); used += dp[v][0].max(dp[v][1] + b[v] + b[cur]); } dp[cur][0] = a[cur] + unused; dp[cur][1] = used; } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut paths = vec![vec![]; n]; for _ in 0..n-1 { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let u = temp[0]-1; let v = temp[1]-1; paths[u].push(v); paths[v].push(u); } let mut dp = vec![vec![-INF; 2]; n]; dfs(0, 0, &a, &b, &paths, &mut dp); println!("{}", dp[0][0].max(dp[0][1])); }