You are given an integer n, representing how many cities there are (numbered from 0 to n-1).
You also receive a list roads, where each element [a, b] means there is a two-way road between city a and city b.
Your task is to assign every city a unique number from 1 to n.
These assigned numbers represent "importance values".
The importance of a single road equals:
You must assign the values in such a way that the total importance of all roads becomes as large as possible.
Return that maximum possible total importance.
Input: n = 4 roads = [[0,1], [1,2], [2,3], [0,3]]
Output: 20
Explanation:
One optimal assignment: Cities → [3, 4, 2, 1] Road importance → (0,1) → 3 + 4 = 7 (1,2) → 4 + 2 = 6 (2,3) → 2 + 1 = 3 (0,3) → 3 + 1 = 4 Total = 22
Input: n = 3 roads = [[0,2], [1,2]]
Output: 9
Explanation:
Assignment: [2, 1, 3] Roads → 2+3 = 5, 1+3 = 4 Total = 9
Accepted:
Submission: