<title>2015 Blue Bridge Cup: 10. Tree of Life</title> 2015 Blue Bridge Cup: 10. Tree of Life
31 cents won't write.
In the X-forest, God created the tree of life.
He gives each node of each tree (the leaf also known as a node) an integer that represents the harmonious value of the point.
God wants to select a non-empty node set S in this tree, so that for any two points in S, a, there is a dot column {A, V1, v2, ..., VK, b} so that each point in this point column is an element of S inside, and there is an edge connected between two adjacent points in the sequence.
In this premise, God wants to make the points in S corresponding to the integers and as large as possible.
This is the greatest and is God's rating of the Tree of life.
Through the efforts of ATM, he already knew God gave every tree on each node of the integer. But because ATM is not good at computing, he does not know how to effectively evaluate the score. He needs you to write a program for him to calculate the score of a tree.
"Input Format"
The first line of an integer n indicates that the tree has n nodes.
The second row n integers, which in turn represent the score for each node.
Next n-1 line, 2 integers per line u, V, indicates the existence of a U to v edge. Since this is a tree, there is no ring.
"Output Format"
The output is a single number indicating the score God gave to this tree.
"Sample Input"
5
1-2-3 4 5
4 2
3 1
1 2
2 5
"Sample Output"
8
"Data Range"
For 30% of data, n <= 10
For 100% of data, 0 < n <= 10^5, the absolute value of each node's score is not more than 10^6
2015 Blue Bridge Cup: 10. Tree of Life