CF1394D Boboniu and Jianghu
Description
Since Boboniu finished building his Jianghu, he has been doing Kungfu on these mountains every day.
Boboniu designs a map for his $ n $ mountains. He uses $ n-1 $ roads to connect all $ n $ mountains. Every pair of mountains is connected via roads.
For the $ i $ -th mountain, Boboniu estimated the tiredness of doing Kungfu on the top of it as $ t_i $ . He also estimated the height of each mountain as $ h_i $ .
A path is a sequence of mountains $ M $ such that for each $ i $ ( $ 1 \le i < |M| $ ), there exists a road between $ M_i $ and $ M_{i+1} $ . Boboniu would regard the path as a challenge if for each $ i $ ( $ 1\le i
Input Format
The first line contains a single integer $ n $ ( $ 2 \le n \le 2 \cdot 10^5 $ ), denoting the number of the mountains.
The second line contains $ n $ integers $ t_1, t_2, \ldots, t_n $ ( $ 1 \le t_i \le 10^6 $ ), denoting the tiredness for Boboniu to do Kungfu on each mountain.
The third line contains $ n $ integers $ h_1, h_2, \ldots, h_n $ ( $ 1 \le h_i \le 10^6 $ ), denoting the height of each mountain.
Each of the following $ n - 1 $ lines contains two integers $ u_i $ , $ v_i $ ( $ 1 \le u_i, v_i \le n, u_i \neq v_i $ ), denoting the ends of the road. It's guaranteed that all mountains are connected via roads.
Output Format
Print one integer: the smallest sum of tiredness of all challenges.
Explanation/Hint
For the first example:
In the picture, the lighter a point is, the higher the mountain it represents. One of the best divisions is:
- Challenge $ 1 $ : $ 3 \to 1 \to 2 $
- Challenge $ 2 $ : $ 5 \to 2 \to 4 $
The total tiredness of Boboniu is $ (30 + 40 + 10) + (20 + 10 + 50) = 160 $ . It can be shown that this is the minimum total tiredness.