Problem list
Log in
#coci00563 · COCI 2020/2021 Contest 1

Papricice

Unrated 1.0 s 256 MB

Afrika paprika! – S.V. After a tiring morning in the garden, Mr. Malnar decided to reward himself with dried hot peppers he grew himself. He has $n$ peppers, connected with $n - 1$ pieces of string, so that every two peppers are connected by some series of strings. Formally, they form a tree. Mr. Malnar will partake in three lunches today. For that purpose, he will cut two strings to get three smaller components, one for each lunch. 1 2 3 4 5 6 7 8 9 The tree from the third example along with the optimal cuts. It’s bad to make any lunch too spicy, so he will choose the cuts in a way that minimises the difference between the size of the largest and the smallest component. You need to determine the sought minimum difference.

Input

The first line contains an integer $n$, the number of peppers. The peppers are labeled by integers from 1 to $n$. Each of the following $n - 1$ lines contains two integers $x$ and $y$ ($1 \le x$, $y \le n$) – labels of peppers that are directly connected by a piece of string.

Output

Print the minimum possible difference of component sizes.

Example 1

Input
4
1 2
2 3
3 4
Output
1

Example 2

Input
6
1 2
1 3
3 4
3 5
5 6
Output
0

Example 3

Input
9
1 3
2 3
3 4
3 5
5 6
5 7
7 8
7 9
Output
2
Source
COCI 2020/2021 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code