#P1352. 没有上司的舞会
没有上司的舞会
Description
A university has employees, numbered .
There is a hierarchy among them, meaning their relationships form a tree rooted at the university president, where a parent node is the direct supervisor of its child nodes.
There will be an anniversary banquet. Inviting an employee increases the happiness index by . However, if an employee’s direct supervisor attends the banquet, that employee will refuse to attend no matter what.
Please compute which employees to invite so that the total happiness index is maximized, and find the maximum total happiness index.
Input Format
The first line contains an integer .
Lines to each contain one integer. The integer on line is the happiness index of employee .
Lines to each contain a pair of integers , meaning is the direct supervisor of .
Output Format
Output a single line with one integer representing the maximum total happiness index.
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
5
Hint
Constraints
- For of the testdata, it is guaranteed that , , , and the given relations form a tree.
Translated by ChatGPT 5
京公网安备 11011102002149号