CF1292C.Xenon's Attack on the Gangs

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

INSPION FullBand Master - INSPION

INSPION - IOLITE-SUNSTONE

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 nn small gangs. This network contains exactly n1n - 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 00 to n2n - 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 SS password layers, with SS being defined by the following formula:

$$S = \sum_{1 \leq u < v \leq n} mex(u, v) $$ </p><p>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$ .</p><p>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.</p><p>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?

输入格式

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

Each of the next n1n - 1 lines contains integers uiu_i and viv_i ( 1ui,vin1 \leq u_i, v_i \leq n ; uiviu_i \neq v_i ), indicating there's a direct link between gangs uiu_i and viv_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.

输出格式

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

输入输出样例

  • 输入#1

    3
    1 2
    2 3

    输出#1

    3
  • 输入#2

    5
    1 2
    1 3
    1 4
    3 5

    输出#2

    10

说明/提示

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

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

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

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

  • mex(1,3)=1mex(1, 3) = 1
  • mex(1,5)=2mex(1, 5) = 2
  • mex(2,3)=1mex(2, 3) = 1
  • mex(2,5)=2mex(2, 5) = 2
  • mex(3,4)=1mex(3, 4) = 1
  • mex(4,5)=3mex(4, 5) = 3

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

首页