Dance Party Without a Boss


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
C++, Python

Anniversary Party

Ural University has N staff members, numbered 1 to N.

Their relationship structure is like a tree rooted at the president. The parent node is the direct supervisor of the child node.

Each staff member has a happiness index Hi (1 ≤ i ≤ N).

Now an anniversary party is to be held. However, no staff member is willing to attend with their direct supervisor.

Under this condition, the organizers want to select a group of staff to attend so that the total happiness index of the attendees is maximized. Find this maximum value.

Input Format

First line: an integer N.

Next N lines: the i-th line gives the happiness index Hi of staff member i.

Next N-1 lines: each line contains two integers L, K, indicating that K is the direct supervisor of L. (Note: the second number is the parent of the first number).

Output Format

Output the maximum possible total happiness index.

Constraints

1 ≤ N ≤ 6000

-128 ≤ Hi ≤ 127

Sample Input

7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5

Sample Output

5

Comments

There are no comments at the moment.