#P7130. 「RdOI R1」平衡常数(balance)
「RdOI R1」平衡常数(balance)
Description
Given a rooted weighted tree with root , the weight of node is denoted by . Let the set of nodes in the subtree rooted at be . Find a node set that satisfies the following conditions:
-
For all , .
-
Maximize .
You only need to output , i.e., the sum of the weights of the selected nodes.
Input Format
The first line contains a positive integer .
The second line contains positive integers .
The next lines each contain two integers , representing the two endpoints of an edge.
Output Format
Output a single line containing the maximum total sum you computed.
3
1 2 3
1 2
1 3
1
Hint
Constraints
| Test Point ID | Special Property | ||
|---|---|---|---|
For of the testdata, , , .
Notes / Hints
- Idea From: LCuter.
File Input/Output (simulation, not needed when submitting code)
- File name:
balance.cpp. - Input file name:
balance.in. - Output file name:
balance.out.
Translated by ChatGPT 5
京公网安备 11011102002149号