Playing with Priority Queues!!! Brute Force | Beginner's Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& val, vector<vector<int>>& edges, int k) {\n        priority_queue<pair<int, int>> pq;\n        int n = val.size();\n        map<int, priority_queue<int>> mp;\n\n        // Populate the adjacency values map\n        for (int i = 0; i < edges.size(); i++) {\n            int a = edges[i][0];\n            int b = edges[i][1];\n            mp[a].push(val[b]);\n            mp[b].push(val[a]);\n        }\n\n        // Add all nodes to the priority queue\n        for (int i = 0; i < n; i++) {\n            pq.push({val[i], i});\n        }\n\n        int ans = INT_MIN;\n\n        // Process each node\n        while (!pq.empty()) {\n            auto it = pq.top();\n            pq.pop();\n            int node = it.second;\n            int curr = it.first;\n\n            ans = max(ans, curr);\n\n            vector<int> use;\n            int count = min(k, (int)mp[node].size());  // Store the limit before looping\n\n            // Get the top k values (or less, if fewer neighbors exist)\n            for (int i = 0; i < count; i++) {\n                curr += mp[node].top();\n                ans = max(ans, curr);\n                use.push_back(mp[node].top());\n                mp[node].pop();\n            }\n\n            for (int i = 0; i < use.size(); i++) {\n                mp[node].push(use[i]);\n            }\n        }\n\n        return ans;\n    }\n};\n\n```
['C++']