Min Heap | Easy 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<int> s
# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n=vals.size();\n        vector<int> score(n,0),e(n,0);\n        unordered_map<int,priority_queue<int,vector<int>,greater<int> > > mm;\n        for(int i=0;i<edges.size();i++){\n            int node1=edges[i][0],node2=edges[i][1];\n            //for node1\n            if(vals[node2]>0 && k>0){\n                if(mm.find(node1)==mm.end()){\n                    mm[node1].push(vals[node2]);\n                    score[node1]+=vals[node2];\n                }else{\n                    if(mm[node1].size()<k){\n                        mm[node1].push(vals[node2]);\n                        score[node1]+=vals[node2];\n                    }else{\n                        if(mm[node1].top()<vals[node2]){\n                            score[node1]-=mm[node1].top();\n                            mm[node1].pop();\n                            score[node1]+=vals[node2];\n                            mm[node1].push(vals[node2]);\n                        }\n                    }\n                }\n            }\n            swap(node1,node2);\n            //for node2\n            if(vals[node2]>0 && k>0){\n                if(mm.find(node1)==mm.end()){\n                    mm[node1].push(vals[node2]);\n                    score[node1]+=vals[node2];\n                }else{\n                    if(mm[node1].size()<k){\n                        mm[node1].push(vals[node2]);\n                        score[node1]+=vals[node2];\n                    }else{\n                        if(mm[node1].top()<vals[node2]){\n                            score[node1]-=mm[node1].top();\n                            mm[node1].pop();\n                            score[node1]+=vals[node2];\n                            mm[node1].push(vals[node2]);\n                        }\n                    }\n                }\n            }\n        }\n        long long int ans=-1e11;\n        for(int i=0;i<n;i++){\n            long long int some=score[i] + vals[i];\n            ans=max(ans,some);\n        }\n        return ans;\n    }\n};\n```
['C++']