Node selection algorithm training
Submit this problem meter records
Resource limitations
Time limit: 1.0 s memory limit: 256.0 MB
Problem description
A n nodes in the tree, a tree each node has a positive integer weights, if a point is selected, then in the tree and its adjacent points can be selected, strives for the selected point weights and what is the biggest?
Input format
The first line contains an integer n,
The next line contains n positive integers, a positive integer representing the ith point the value of I
Next, a total of n - 1 row, each row describes an edge in the tree,
The output format
Output an integer, representatives elected by the weight and the maximum,
The sample input
5
1, 2, 3, 4, 5
1
21 3
2 4
2 5
Sample output
12
The sample description
Select number three, four, five points, weights and for 3 + 4 + 5=12,
The data size and agreed
About 20% of the data, n & lt;=20,
About 50% of the data, n & lt;=1000,
About 100% of the data, n & lt;=100000,
Weights are positive integers less than 1000,