C++ solution using min priority queue
Approach\nFor each node we will have priority queue to maintain sum of top k elements and a varible to track the max star sum possible for that node.\n\n\n# Cod
# Approach\nFor each node we will have priority queue to maintain sum of top k elements and a varible to track the max star sum possible for that node.\n\n\n# Code\n```\nclass Solution {\n    struct node{\n        priority_queue<int,vector<int>,greater<int>>pq;\n        int sum = 0;\n    };\npublic:\n    int maxStarSum(vector<int>& val, vector<vector<int>>& edges, int k) {\n        int n = val.size();\n        vector<node>adj(n);\n        for(int i=0;i<n;i++) adj[i].sum=val[i];\n        for(auto&i:edges){\n            int u = i[0], v = i[1];\n            if(val[v]>0){\n                adj[u].pq.push(val[v]);\n                adj[u].sum+=val[v];\n                if(adj[u].pq.size()>k){\n                    adj[u].sum-=adj[u].pq.top();\n                    adj[u].pq.pop();\n                }\n            }\n            if(val[u]>0){\n                adj[v].pq.push(val[u]);\n                adj[v].sum+=val[u];\n                if(adj[v].pq.size()>k){\n                    adj[v].sum-=adj[v].pq.top();\n                    adj[v].pq.pop();\n                }\n            }\n        }\n        int ans = INT_MIN;\n        for(auto&i:adj){\n            ans = max(ans,i.sum);\n        }\n        return ans;\n    }\n};\n```
['C++']