Max Heap + Hash Table || Easy C++ ✅✅
Approach\n Describe your approach to solving the problem. \nUse a priority queue to store the top k max value adjacent nodes for\neach node.\n\n# Complexity\n- 
# Approach\n<!-- Describe your approach to solving the problem. -->\nUse a priority queue to store the top k max value adjacent nodes for\neach node.\n\n# Complexity\n- Time complexity: O(N * log(K))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N*K)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& val, vector<vector<int>>& e, int k) {\n        unordered_map<int,priority_queue<int,vector<int>,greater<int>>> adj;\n        int ans = INT_MIN;\n        for(int i = 0;i<e.size();i++)\n        {\n            adj[e[i][0]].push(val[e[i][1]]);\n            adj[e[i][1]].push(val[e[i][0]]);\n            if(adj[e[i][0]].size()>k) adj[e[i][0]].pop();\n            if(adj[e[i][1]].size()>k) adj[e[i][1]].pop();\n        }\n\n        for(int i = 0;i<val.size();i++)\n        {\n            if(adj.find(i)!=adj.end())\n            {\n               priority_queue<int,vector<int>,greater<int>> q = adj[i];\n               int count = 0;\n               while(!q.empty())\n               {\n                   count = (q.top())>0 ? count+q.top() :count;\n                   q.pop();\n               }\n               ans = max(ans,count+val[i]);\n            }\n            else ans = max(ans,val[i]);\n        }\n        return ans;  \n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/676904a2-9185-4f08-b210-84bf1d80ac30_1692333325.989491.jpeg)\n
['Hash Table', 'Heap (Priority Queue)', 'C++']