Codeforces Round 569 (Div. 1)
D
Fedor Runs for President
Codeforces
2700
原题
← CE →
翻译中…

Fedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tree (connected graph without cycles). Fedor's team has found out in the ministry of transport of Byteland that there is money in the budget only for one additional road. In the debates, he is going to say that he will build this road as a way to maximize the number of distinct simple paths in the country. A simple path is a path which goes through every vertex no more than once. Two simple paths are named distinct if sets of their edges are distinct.

翻译中…

But Byteland's science is deteriorated, so Fedor's team hasn't succeeded to find any scientists to answer how many distinct simple paths they can achieve after adding exactly one edge on the transport system?

翻译中…

Help Fedor to solve it.

翻译中…

An edge can be added between vertices that are already connected, but it can't be a loop.

翻译中…

In this problem, we consider only simple paths of length at least two.

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($2 \leq n \leq 500\ 000$) — number of vertices in Byteland's transport system.

翻译中…

Each of the following $n - 1$ lines contains two integers $v_i$ and $u_i$ ($1 \leq v_i, u_i \leq n$). It's guaranteed that the graph is tree.

翻译中…

Output

翻译中…

Print exactly one integer — a maximal number of simple paths that can be achieved after adding one edge.

翻译中…

样例

Input #1
2
1 2
Output #1
2
InputCopy OutputCopy
Input #2
4
1 2
1 3
1 4
Output #2
11
InputCopy OutputCopy
Input #3
6
1 2
1 3
3 4
3 5
4 6
Output #3
29
InputCopy OutputCopy
题目信息
题号
1179D
时间限制
2 s
内存限制
256 MB
标签
数据结构
动态规划
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。