#P1922. 女仆咖啡厅桌游吧

女仆咖啡厅桌游吧

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 11 as the root, the planning bureau requires: for every non-leaf node ii, let cafeicafe_i be the number of maid cafes and tableitable_i be the number of board game bars in its subtree (including itself). It must hold that cafei=tableicafe_i = table_i.

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 nn, the number of nodes in the world.

Lines 22 through nn each contain two positive integers uu, vv, indicating that there is an edge between uu and vv.

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 30%30\% of the testdata, it is guaranteed that n20n \le 20.
  • For 100%100\% of the testdata, it is guaranteed that 1n1051 \le n \le 10^5, 1u,vn1 \le u, v \le n.

Translated by ChatGPT 5