Edges in Heap
Intuition\nTry taking every node as the center and at most k neighbouring nodes wiht max positive values. \n Describe your first thoughts on how to solve this p
# Intuition\nTry taking every node as the center and at most `k` neighbouring nodes wiht max positive values. \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\npushing all the positive value of the neighbouring nodes to a priority queue (max heap) and extracting `k` from them and caculating the sum of each node as center.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: *`O(nlogn)`*\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: *`O(n)`*\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n = vals.size(), get;\n        vector<priority_queue<int>> star(n);\n        for(vector<int>& edge: edges) {\n            if(vals[edge[0]] > 0)\n                star[edge[1]].push(vals[edge[0]]);\n            if(vals[edge[1]] > 0)\n                star[edge[0]].push(vals[edge[1]]);\n        }\n        vector<int> center(vals.begin(), vals.end());\n        for(int i = 0; i < n; i++) {\n            get = k;\n            while(get-- && !star[i].empty()) {\n                center[i] += star[i].top();\n                star[i].pop();\n            }\n        }\n        return *max_element(center.begin(), center.end());\n    }\n};\n```
['Greedy', 'Graph', 'Heap (Priority Queue)', 'C++']