Skip to content

Commit 19ae111

Browse files
authored
Create 2285. Maximum Total Importance of Roads (#515)
2 parents 83f0b0e + f9e4aa8 commit 19ae111

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
long long maximumImportance(int n, vector<vector<int>>& roads) {
4+
ios::sync_with_stdio(false);
5+
cin.tie(nullptr);
6+
7+
vector<int> degree(n);
8+
9+
for (auto &it : roads) {
10+
degree[it[0]]++;
11+
degree[it[1]]++;
12+
}
13+
14+
sort(degree.begin(), degree.end());
15+
long long ans = 0;
16+
17+
while(n) {
18+
ans += (long long)degree[n - 1] * n;
19+
n--;
20+
}
21+
22+
return ans;
23+
}
24+
};

0 commit comments

Comments
 (0)