Let’s get straight to the point. You are given a tree. In the tree, each node has a number assigned to it. The score of a node is defined as the of all the numbers on the simple path from to .
Suppose, . The list of values on the path from to the node is . The minimum non-negative excluded number or of this list is . So the score of node is .
You have to print the maximum score among all the nodes.
A tree is a connected graph with nodes and edges.
The MEX of a list of numbers is the minimum non-negative number that is not included in the list. For example, .
The first line contains an integer — the number of nodes.
The second line contains integers .
Each of the next lines contains 2 values and , indicating that there is an edge between and in the tree.
Print one integer — the maximum score among all the nodes.
Input | Output |
---|---|
6 0 2 1 4 21 2 1 2 2 4 1 3 3 5 3 6 | 3 |
score of node is score of node is score of node is score of node is score of node is score of node is Hence, the maximum score among all the nodes is . |