2285.cpp (440B)
1 class Solution { 2 3 typedef pair<int, int> pii; 4 5 public: 6 long long maximumImportance(int n, vector<vector<int>> &roads) { 7 vector<int> count(n, 0); 8 9 for (auto &e : roads) { 10 count[e[0]]++; 11 count[e[1]]++; 12 } 13 14 sort(count.begin(), count.end()); 15 16 long long res = 0ll; 17 for (int i = 0; i < n; i++) 18 res += (i + 1ll) * count[i]; 19 20 return res; 21 } 22 };