D. [GESP202609 六级] 分树规划

    远端评测题 1000ms 512MiB

[GESP202609 六级] 分树规划

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Description

A teacher has a tree with nn nodes, numbered 1,2,…,n1,2,\ldots,n in order.

The teacher wants to give this tree as a prize to two students. Specifically, the teacher will choose one edge and delete it from the tree, thereby splitting the tree into two connected components. Each student will receive one of the connected components.

If one student gets a component whose number of nodes is obviously smaller than the other student's, that student may feel unhappy. To avoid this, the teacher wants to know what the minimum possible absolute difference between the sizes (number of nodes) of the two components is.

Input Format

The first line contains a positive integer nn, representing the number of nodes.

The next n−1n-1 lines each contain two positive integers ui,viu_i, v_i, representing an edge connecting nodes uiu_i and viv_i.

Output Format

Output one line with one integer, representing the answer.

4
1 2
2 3
3 4
0
6
1 2
1 3
1 4
1 5
5 6
2

Hint

For 40%40\% of the testdata, it is guaranteed that 2≤n≤5002\le n\le 500.

For all testdata, it is guaranteed that 2≤n≤2×1042\le n\le 2\times 10^4.

Translated by ChatGPT 5

11月第3周刷题

未认领
状态
已结束
题目
6
开始时间
2026-11-18 0:00
截止时间
2026-11-26 23:59
可延期
24 小时