cswork / OAOpen practice workspace

MicrosoftOA #9

Assign Values

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyHashing

Assign the values 1..N to the N vertices, using each value exactly once. Find the maximum total, over all edges, of the sum of the values at the two endpoints. The original site's example edge arrays had inconsistent lengths, so this site rewrote the input from the four edges described in the text.

Input

This site's input: the first line contains N M (1≤N≤100000, 0≤M≤200000), followed by M lines, each an undirected edge u v, with vertices numbered 1..N; the graph is guaranteed to be simple.

Output

Output a single integer, the answer.

Example 1

Input:

5 4
2 3
2 1
1 4
2 4

Output:

31

Example 2

Input:

1 0

Output:

0

Example 3

Input:

3 2
1 2
2 3

Output:

9

Example notes

Example 1: the degrees sorted are 0, 1, 2, 2, 3; multiplying them by 1, 2, 3, 4, 5 respectively gives a total of 31.

Example 2: there are no edges, so every assignment gives a total of 0.

Example 3: assign 3 to the center and 1, 2 to the ends; the edge sums are 4+5=9.

Editorial

Loading solution…