C++ || Graphs || Easy approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(n*logn)\n\n- Space complexity:O(n)\n\n# Code\n\nclass Solution {\npublic:\n    int ma
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:$$O(n*logn)$$\n\n- Space complexity:$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n=vals.size();\n        if(k==0){\n            return *max_element(vals.begin(), vals.end());\n        }\n        map<int, vector<pair<int, int>>>m;\n        for(auto it: edges){\n            m[it[0]].push_back({vals[it[1]], it[1]});\n            m[it[1]].push_back({vals[it[0]], it[0]});\n        }\n        int ans=-1e9;\n        for(int i=0; i<n; i++){\n            sort(m[i].begin(), m[i].end());\n            reverse(m[i].begin(), m[i].end());\n            int cnt=vals[i], k1=k;\n            ans=max(ans, cnt);\n            for(auto it: m[i]){\n                cnt+=it.first;\n                k1--;\n                ans=max(ans, cnt);\n                if(it.first<0 || k1==0){\n                    break;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Array', 'Greedy', 'Graph', 'Sorting', 'C++']