2285. Maximum Total Importance of Roads

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2285

class Solution:
    def maximumImportance(self, n: int, roads: List[List[int]]) -> int:
        deg = [0] * n
        for a, b in roads:
            deg[a] += 1
            deg[b] += 1
        deg.sort()
        return sum(i * v for i, v in enumerate(deg, 1))