✅✅✅ C++ Solution Using DFS & Priority Queue || Very Simple & Easy to Understand
Up Vote if you like the solution\n\n/*\nApproach is to traverse the graph to each node and at each node check for the max possible sum with at most k connected 
<b>Up Vote if you like the solution\n```\n/*\nApproach is to traverse the graph to each node and at each node check for the max possible sum with at most k connected node.\nAs it says max value and at most k nodes we need to skip -ve value as it will always redule the value.\n\nSteps:\n1. create a graph using the edges given.\n2. Traverse to each node using dfs.\n    - On each node create a priority queue to get sum of the max k nodes values \n    - Traverse to next connected node and get max possible value \n    - return max value among current node and the max value recieved from its connected node.\n*/\n\nclass Solution {\npublic:\n    int dfs(vector<vector<int>> &g, vector<int> &vis, int node, int k, vector<int> &val){\n        priority_queue<int> pq;\n        int res = INT_MIN;\n        vis[node] = 1;\n        for(auto i: g[node] ){\n            if(val[i] > 0) pq.push(val[i]);\n            if(vis[i] == 0) res = max(res, dfs(g, vis, i, k, val));\n        }\n        int sum = val[node];            //sum stores the max possible value when node is considered as the centre\n        while(k > 0 && pq.size() > 0){\n            sum += pq.top();\n            pq.pop();\n            k--;\n        }\n        return max(sum, res);\n    }\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int ans = INT_MIN, n = vals.size();\n        vector<vector<int>> g(n);\n        vector<int> vis(n, 0);\n        for(auto e: edges){ g[e[0]].push_back(e[1]);  g[e[1]].push_back(e[0]); }    //create graph                  \n        for(int i = 0; i < n; ++i){  //traverse to all nodes, lope required as the graph may be dissconnected \n            if(vis[i] == 0) ans = max(ans, dfs(g, vis, i, k, vals));\n        }\n        return ans;\n    }\n};\n```
['C++']