Codeforces Round 322 (Div. 2)
F
Zublicanes and Mumocrates
Codeforces
2400
原题
← E→
翻译中…

It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on $*n*$ main squares of the capital of Berland. Each of the $*n*$ squares certainly can have demonstrations of only one party, otherwise it could lead to riots. On the other hand, both parties have applied to host a huge number of demonstrations, so that on all squares demonstrations must be held. Now the capital management will distribute the area between the two parties.

翻译中…

Some pairs of squares are connected by $(*n* - 1)$ bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares.

翻译中…

The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even.

翻译中…

To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($2 ≤ *n* ≤ 5000$) — the number of squares in the capital of Berland.

翻译中…

Next $*n* - 1$ lines contain the pairs of integers $*x*, *y*$ ($1 ≤ *x*, *y* ≤ *n*, *x* ≠ *y*$) — the numbers of the squares connected by the road. All squares are numbered with integers from $1$ to $*n*$. It is guaranteed that the number of dead end squares of the city is even.

翻译中…

Output

翻译中…

Print a single number — the minimum number of roads connecting the squares with demonstrations of different parties.

翻译中…

样例

Input #1
8
1 4
2 4
3 4
6 5
7 5
8 5
4 5
Output #1
1
InputCopy OutputCopy
Input #2
5
1 2
1 3
1 4
1 5
Output #2
2
InputCopy OutputCopy
题目信息
题号
581F
时间限制
3 s
内存限制
512 MB
标签
动态规划
树
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。