Simple C++ Solution
Code\n\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n = vals.size();\n        vector<vect
# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n = vals.size();\n        vector<vector<int>> valid_edges(n);\n        for(int i=0;i<edges.size();i++){\n            if(vals[edges[i][1]] > 0)\n                valid_edges[edges[i][0]].push_back(vals[edges[i][1]]);\n            if(vals[edges[i][0]] > 0)\n                valid_edges[edges[i][1]].push_back(vals[edges[i][0]]);\n        }\n        int mx = INT_MIN;\n        for(int i=0;i<n;i++){\n            sort(valid_edges[i].rbegin(),valid_edges[i].rend());\n            int tmp = vals[i];\n            int cnt = min(k,(int)valid_edges[i].size());\n            for(int j=0;j<cnt;j++)\n                tmp += valid_edges[i][j];\n            mx = max(mx,tmp);\n        }\n        return mx;\n    }\n};\n```
['Array', 'Graph', 'Sorting', 'C++']