2015 Blue Bridge Cup: 10. Tree of Life

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.