Codeforces Round 614 (Div. 1)
C
Xenon's Attack on the Gangs
Codeforces
2300
原题
← BD →
翻译中…

On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight against the gangs of the cyber world.

翻译中…

His target is a network of $n$ small gangs. This network contains exactly $n - 1$ direct links, each of them connecting two gangs together. The links are placed in such a way that every pair of gangs is connected through a sequence of direct links.

翻译中…

By mining data, Xenon figured out that the gangs used a form of cross-encryption to avoid being busted: every link was assigned an integer from $0$ to $n - 2$ such that all assigned integers are distinct and every integer was assigned to some link. If an intruder tries to access the encrypted data, they will have to surpass $S$ password layers, with $S$ being defined by the following formula:

翻译中…

$$S = \sum_{1 \leq u \lt v \leq n} mex(u, v)$$

翻译中…

Here, $mex(u, v)$ denotes the smallest non-negative integer that does not appear on any link on the unique simple path from gang $u$ to gang $v$.

翻译中…

Xenon doesn't know the way the integers are assigned, but it's not a problem. He decides to let his AI's instances try all the passwords on his behalf, but before that, he needs to know the maximum possible value of $S$, so that the AIs can be deployed efficiently.

翻译中…

Now, Xenon is out to write the AI scripts, and he is expected to finish them in two hours. Can you find the maximum possible $S$ before he returns?

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($2 \leq n \leq 3000$), the number of gangs in the network.

翻译中…

Each of the next $n - 1$ lines contains integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$; $u_i \neq v_i$), indicating there's a direct link between gangs $u_i$ and $v_i$.

翻译中…

It's guaranteed that links are placed in such a way that each pair of gangs will be connected by exactly one simple path.

翻译中…

Output

翻译中…

Print the maximum possible value of $S$ — the number of password layers in the gangs' network.

翻译中…

Note

翻译中…

In the first example, one can achieve the maximum $S$ with the following assignment:

翻译中…

image

翻译中…

With this assignment, $mex(1, 2) = 0$, $mex(1, 3) = 2$ and $mex(2, 3) = 1$. Therefore, $S = 0 + 2 + 1 = 3$.

翻译中…

In the second example, one can achieve the maximum $S$ with the following assignment:

翻译中…

image

翻译中…

With this assignment, all non-zero mex value are listed below:

翻译中…
  • $mex(1, 3) = 1$
  • $mex(1, 5) = 2$
  • $mex(2, 3) = 1$
  • $mex(2, 5) = 2$
  • $mex(3, 4) = 1$
  • $mex(4, 5) = 3$
翻译中…

Therefore, $S = 1 + 2 + 1 + 2 + 1 + 3 = 10$.

翻译中…

样例

Input #1
3
1 2
2 3
Output #1
3
InputCopy OutputCopy
Input #2
5
1 2
1 3
1 4
3 5
Output #2
10
InputCopy OutputCopy
题目信息
题号
1292C
时间限制
3 s
内存限制
512 MB
标签
组合数学
DFS 及类似
动态规划
贪心
树

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