diff --git a/2285. Maximum Total Importance of Roads b/2285. Maximum Total Importance of Roads new file mode 100644 index 0000000..b6b707b --- /dev/null +++ b/2285. Maximum Total Importance of Roads @@ -0,0 +1,24 @@ +class Solution { +public: + long long maximumImportance(int n, vector>& roads) { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + vector degree(n); + + for (auto &it : roads) { + degree[it[0]]++; + degree[it[1]]++; + } + + sort(degree.begin(), degree.end()); + long long ans = 0; + + while(n) { + ans += (long long)degree[n - 1] * n; + n--; + } + + return ans; + } +};