Untitled
unknown
plain_text
2 years ago
602 B
5
Indexable
from collections import defaultdict
class Solution:
def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
degree = defaultdict(int)
for a, b in roads:
degree[a] += 1
degree[b] += 1
items = sorted(degree.items(), key = lambda x: x[1], reverse = True)
counter = n
assignment = {}
for item, _ in items:
assignment[item] = n
n -= 1
ans = 0
for a, b in roads:
ans += assignment[a] + assignment[b]
return ans
Editor is loading...
Leave a Comment