C++ VERY EASY SOLUTION | EASY TO UNDERSTAND
\n# Approach\nConsider every node is center node and from that push it\'s neighbour nodes value in priority_queue.\n\n\n\n\n# Code\n```\nclass Solution {\npubli
\n# Approach\nConsider every node is center node and from that push it\'s neighbour nodes value in priority_queue.\n\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> graph;\n    int ans;\n    void solve(int src, vector<int>& vals, int k) {\n        priority_queue<int> pq;\n\n        for(auto &nebr: graph[src]) {\n            pq.push(vals[nebr]);\n        }\n\n        int sum = vals[src];\n        ans = max(ans, sum);    // for -ve node val\n        for(int i = 0; i < k && !pq.empty(); i++) {\n            sum += pq.top();\n            ans = max(ans, sum);\n            pq.pop();\n        }\n    }\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n = int(vals.size());\n        graph = vector<vector<int>> (n + 1);\n        ans = INT_MIN;\n        for(auto &e: edges) {\n            graph[e[0]].push_back(e[1]);\n            graph[e[1]].push_back(e[0]);\n        }\n        for(int i = 0; i < n; i++) {\n            solve(i, vals, k);\n        }\n        return ans;\n    }\n};
['C++']