Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
548 B
6
Indexable
Never
class Solution {
public:
    long long maximumImportance(int n, vector<vector<int>>& roads) {
        vector < int > degree(n, 0);
        
        for(int i=0;i<roads.size();i++) {
            degree[roads[i][0]]++;
            degree[roads[i][1]]++;
        }
        
        sort(degree.begin(),degree.end());
        
        long long value = 1, importance = 0;
        
        for(int i=0;i<degree.size();i++) {
            importance+=value*(long long) degree[i];
            value++;
        }
        
        return importance;
    }
};
Leave a Comment