c++ solution, simple to understand logic with comments
Intuition\n1. first find all neighbours of each node so that each node can be considered as center of star graph\n2. sort the neighbours in descending order bas
# Intuition\n1. first find all neighbours of each node so that each node can be considered as center of star graph\n2. sort the neighbours in descending order based on their values so we can take first k that have more values\n\n# Complexity\n- Time complexity:\n$$O(n^2 * \\log n)$$\n\n- Space complexity:\n$$O(n^2)$$\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n = vals.size();\n        // create 2d vector where i = current node i.e. center of star graph and j\'s are neighbour nodes of node i or all neighbours of center of star graph\n        vector<vector<int>> node_neighbours(n,vector<int>());\n        for(int i=0; i<edges.size();i++){\n            node_neighbours[edges[i][0]].push_back(edges[i][1]);\n            node_neighbours[edges[i][1]].push_back(edges[i][0]);\n        }\n        // assign values to neighbours\n        vector<vector<int>> neighbour_values(n,vector<int>());\n        for(int i=0;i<n;i++){\n            for(int j=0;j<node_neighbours[i].size();j++){\n                neighbour_values[i].push_back(vals[node_neighbours[i][j]]);\n            }\n            // sort each vector of neighbour_values in descending order so that we can get max sum of first k indices from that sorted vector \n            auto comp = [](int a, int b){ return a>b;};\n            sort(neighbour_values[i].begin(),neighbour_values[i].end(), comp);\n        }\n\n        // find max possible sum of first k+1 elements in neighbour_values\n        int maxSum = INT_MIN;\n        for(int i=0;i<n;i++){\n            int curr_sum = vals[i]; // add current node val i.e center of the star graph, we have to take\n            for(int j=0;j<min(k,(int)neighbour_values[i].size());j++){ // max we can take k neighbours more as we have already taken center in the line above\n                if(neighbour_values[i][j]<0){ // if negative then break, and check other center\n                    break;\n                }\n                curr_sum += neighbour_values[i][j];\n            }\n            maxSum = max(maxSum, curr_sum);\n        }\n        \n\n        // uncomment for visualization\n        // for(int i=0;i<n;i++){\n        //     for(int j=0;j<node_neighbours[i].size();j++){\n        //         cout<<node_neighbours[i][j]<<" ";\n        //     }\n        //     cout<<endl;\n        // }\n        // for(int i=0;i<n;i++){\n        //     for(int j=0;j<neighbour_values[i].size();j++){\n        //         cout<<neighbour_values[i][j]<<" ";\n        //     }\n        //     cout<<endl;\n        // }\n        return maxSum;\n        \n    }\n};\n```
['C++']