#P3478. [POI 2008] STA-Station

    ID: 2533 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp树形结构2008POISpecial JudgeO2优化

[POI 2008] STA-Station

Description

Given a tree with nn nodes, find a node such that when this node is chosen as the root, the sum of depths of all nodes is maximized.

The depth of a node is defined as the number of edges on the simple path from that node to the root.

Input Format

The first line contains an integer nn, the number of nodes in the tree.
The next (n1)(n - 1) lines each contain two integers u,vu, v, indicating that there is an edge connecting uu and vv.

Output Format

This problem uses Special Judge.

Output one line with an integer, the index of the chosen node. If multiple nodes satisfy the requirement, output any one of them.

8
1 4
5 6
4 5
6 7
6 8
2 4
3 4

7

Hint

Sample 1 Explanation:

Outputting 77 or 88 are both correct answers.

Constraints:

For all test points, it is guaranteed that 1n1061 \leq n \leq 10^6, 1u,vn1 \leq u, v \leq n, and the input is a tree.

Translated by ChatGPT 5