Edges to Graph
\n# Code\n\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k,int ans = INT_MIN) {\n        vector<int> adj[(in
\n# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k,int ans = INT_MIN) {\n        vector<int> adj[(int)vals.size()];\n        for(auto e:edges) {\n            if(vals[e[1]]>0)adj[e[0]].push_back(vals[e[1]]);\n            if(vals[e[0]]>0)adj[e[1]].push_back(vals[e[0]]);\n        }\n        for(int i = 0;i<vals.size(); i++) {\n            sort(adj[i].rbegin(), adj[i].rend());\n            int sum = vals[i];\n            for(int j = 0; j < min(k,(int)adj[i].size());j++) sum += adj[i][j];\n            ans = max(ans,sum);\n        }\n        return ans;\n    }\n};\n```
['C++']