#P7165. [COCI 2020/2021 #1] Papričice
[COCI 2020/2021 #1] Papričice
Problem Description
Given a tree with nodes, the nodes are numbered from to .
Now you need to cut (remove) two edges. This will split the tree into three connected components. Suppose the numbers of nodes in these three components are . Your task is to minimize , and output this minimum value.
Input Format
The first line contains an integer , the number of nodes in the tree.
The next lines each contain two integers , representing an edge of the tree.
Output Format
Output one integer in a single line, representing the answer.
4
1 2
2 3
3 4
1
6
1 2
1 3
3 4
3 5
5 6
0
9
1 3
2 3
3 4
3 5
5 6
5 7
7 8
7 9
2
Hint
Sample 1 Explanation
An optimal solution can make the sizes of the three connected components , so the output is .
Sample 2 Explanation
Cut the edge between node and node , and the edge between node and node . The three resulting connected components have the same number of nodes.
Sample 3 Explanation
As shown in the figure below:

Constraints
This problem uses bundled testdata.
- Subtask 1 (15 pts): .
- Subtask 2 (35 pts): .
- Subtask 3 (60 pts): .
For of the testdata, .
The full score for this problem is points.
Notes
Translated from Croatian Open Competition in Informatics 2020 ~ 2021 Round 1 D Papričice 。
Translated by ChatGPT 5