luogu#P1922. 女仆咖啡厅桌游吧
女仆咖啡厅桌游吧
Background
Xiao V (小 v) takes his cute little sister out to play. The sister wants to go to a maid cafe, while Xiao V wants to go to a board game bar.
Sister: "I’ll ask you a question. If you get it wrong, you’ll be my slave for a day. If you get it right, I’ll listen to you for the whole day."
Xiao V: "You’ll listen to me for everything!?"
Sister: "Heehee, you’d better just answer the question!"
To secure a happy day for himself, Xiao V comes to you for help.
Problem Description
Xiao V’s world is organized as a tree. At each node, you may build a maid cafe, a board game bar, or leave it empty. After fixing node as the root, the planning bureau requires: for every non-leaf node , let be the number of maid cafes and be the number of board game bars in its subtree (including itself). It must hold that .
The sister’s question is: what is the maximum number of maid cafes that can be placed on this tree?
Input Format
The first line contains a positive integer , the number of nodes in the world.
Lines through each contain two positive integers , , indicating that there is an edge between and .
Output Format
Output a single line with the maximum possible number of maid cafes.
5
1 2
2 3
3 4
2 5
2
Hint
Constraints
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , .
Translated by ChatGPT 5