#P1395. 会议

    ID: 389 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>图论树形结构福建省历届夏令营

会议

Description

There is a village with nn villagers, connected by n1n-1 paths so that all nn homes are connected. Each path has length 11. The village head wants to hold a meeting at some villager’s home. He wants the sum of distances from all villagers to the meeting place to be minimal. Which villager’s home should be chosen, and what is the minimum total distance? If multiple nodes meet the condition, choose the node with the smallest index.

Input Format

The first line contains an integer nn, the number of villagers.

The next n1n-1 lines each contain two integers aa and bb, indicating that there is a path between villager aa and villager bb.

Output Format

Output two integers xx and yy in one line.

Here, xx is the villager’s home where the meeting will be held.

yy is the minimum possible sum of distances.

4
1 2 
2 3 
3 4 

2 4

Hint

Constraints

For 70%70\% of the testdata, n103n \le 10^3.

For 100%100\% of the testdata, n5×104n \le 5 \times 10^4.

Translated by ChatGPT 5