#P3408. 恋爱
恋爱
Description
Xiao A fell in love with Xiao B!!! However, Xiao A is too weak compared to Xiao B, so she would certainly not agree to Xiao A’s request. After Xiao A’s persistent pursuit, Xiao B set the following conditions:
- Xiao B has subordinates (excluding Xiao B) forming a tree structure. Xiao B is at the top, and everyone else has exactly one direct superior.
- Xiao B is numbered , and others are numbered .
- For the -th person: if this person has no subordinates, then Xiao A can give them yuan, after which they will write a letter to their direct superior, stating that Xiao A is confessing to Xiao B.
- If at least a proportion of among their direct subordinates write letters stating that Xiao A is confessing to Xiao B, then they will also write a letter to their direct superior.
- If at least a proportion of among Xiao B’s direct subordinates write letters stating that Xiao A is confessing to Xiao B, then she will agree to Xiao A’s request.
Please determine the minimal total amount of money Xiao A needs to pay to make Xiao B accept Xiao A’s confession.
Input Format
The first line contains three integers .
Then follow lines. The -th line contains two integers , where is the direct superior of , and it is guaranteed that .
Output Format
Output the minimal total amount of money needed.
14 5 3
0 3
0 3
1 10
1 10
2 3
2 10
2 3
5 10
7 10
5 10
7 10
5 10
7 10
5 10
50
Hint
- For of the testdata, the number of people without direct subordinates .
- For of the testdata, .
- Additionally, for of the testdata, .
- Additionally, for of the testdata, and for people with direct subordinates .
- Additionally, for of the testdata, .
- For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号