Cut the Tree
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Assume we walk along the shortest path from node  to node  in the weighted tree . List the values of passing nodes (including  and ) on the sequence in order, and denote  as the length of Longest Increasing Subsequence for that sequence. Further denote  as:



After removing node  in an unrooted tree , we collect the remaining subtrees as a set and call it S_k.

Denote G_k(S) as:



Now you are given a weighted tree  with  nodes, you should determine a node  so that the value of G_k(S) is minimum. In other words, please calculate:




输入描述:

The first line of input contains one integer , indicating the number of nodes.

In the next  lines, there are two integers  in a line, describing the -th edge on the tree.

There are  integers  in the last line, a_i indicates the value on the node .

输出描述:

Output one integer in a line, indicating .
示例1

输入

复制
6
1 2
2 3
3 4
4 5
5 6
1 2 3 4 5 6

输出

复制
3