#P10641. BZOJ3252 攻略
BZOJ3252 攻略
Background
As everyone knows, Katsuragi Keima is the god of “walkthroughs”. After turning on god mode, he can play through games at the same time.
Today he got a new game called XX Peninsula. This game has scenes. From some scenes, you can reach other scenes through different choices. All scenes and choice branches form a tree structure: when the game starts, you are at the root node (common route), and the leaf nodes are endings. Each scene has a value. Now Keima turns on god mode and plays through this game times at the same time. What is the maximum possible total value of the scenes he gets to watch? (Watching the same scene multiple times does not give the value repeatedly.)
“Why do you already know the value of each scene before playing?”
“I have already seen the ending.”
Problem Description
Given a tree with nodes. Each node has a positive integer weight. Select simple paths that start from the root node and end at leaf nodes. Find the maximum possible sum of the weights of all nodes in the union of these paths.
Input Format
The first line contains two positive integers .
The second line contains positive integers , representing the weight of each node.
Then follow lines. Each line contains two positive integers , meaning node is the parent of node .
Output Format
Output one positive integer, the answer.
5 2
4 3 2 1 1
1 2
1 5
2 3
2 4
10
Hint
For all testdata, it is guaranteed that , and .
Translated by ChatGPT 5