#d11304. 最大化深度和

最大化深度和

Maximize Sum of Depths

Problem Description

Given a tree with nn nodes, find a node to serve as the root such that the sum of the depths of all nodes is maximized. Output that maximum sum of depths.

Note: the depth of the root is 11.

Input Format

The first line contains an integer nn, the number of nodes in the tree.

The following (n−1)(n-1) lines each contain two integers u,vu, v, indicating an edge connecting uu and vv.

Output Format

Output one positive integer: the maximum sum of depths.

Sample Input

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

Sample Output

28

Constraints

0≤n≤1060 \le n \le 10^6. That is, an empty tree may exist.

1≤u,v≤n1 \le u, v \le n, and the given edges are guaranteed to form a tree.