eolymp
bolt
Try our new interface for solving problems
Problems

Anniversary Party

Anniversary Party

The president of the Ural State University is going to make an \textbf{80}'th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor relation forms a tree rooted at the president. Employees are numbered by integer numbers in a range from \textbf{1} to \textbf{N}. The personnel office has ranked each employee with a conviviality rating. In order to make the party fun for all attendees, the president does not want both an employee and his or her immediate supervisor to attend. Your task is to make up a guest list with the maximal conviviality rating of the guests. \InputFile The first line of the input contains a number \textbf{N}. \textbf{1} ≤ \textbf{N} ≤ \textbf{6000}. Each of the subsequent \textbf{N} lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from \textbf{--128} to \textbf{127}. After that the supervisor relation tree goes. Each line of the tree specification has the form \begin{verbatim} <L> <K>\end{verbatim}which means that the \textbf{K}-th employee is an immediate supervisor of \textbf{L}-th employee. Input is ended with the line \begin{verbatim} 0 0\end{verbatim}\OutputFile The output should contain the maximal total rating of the guests.
Time limit 1 second
Memory limit 16 MiB
Input example #1
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
Output example #1
5
Author Marat Bakirov
Source Ural State University Internal Contest October 2000 Students Session