C++ Solution
Code\n\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        vector<int> g[100005];\n        int n = v
# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        vector<int> g[100005];\n        int n = vals.size();\n        for(auto x: edges) {            \n            if(vals[x[1]] > 0) g[x[0]].push_back(vals[x[1]]);\n            if(vals[x[0]] > 0) g[x[1]].push_back(vals[x[0]]);\n        }\n        for(int i=0; i<n; i++) {\n            sort(g[i].rbegin(), g[i].rend());\n            for(int j=1; j<g[i].size(); j++) g[i][j] += g[i][j-1];\n        }\n        int ans = INT_MIN;\n        for(int i=0; i<n; i++) {\n            int cnt = vals[i];\n            if(k and g[i].size()) {\n                if(k <= g[i].size()) cnt += g[i][k-1];\n                else cnt += g[i].back();\n            }\n            ans = max(ans, cnt);\n        }\n        return ans;\n    }\n};\n```
['C++']