C++ || Simple Sort || Explained || Easy to understand
So a star graph is a graph having one node [center node] which is connected to all other nodes directly \n\nSo why not try all nodes "as the center of star grap
So a star graph is a graph having **one node [center node] which is connected to all other nodes directly** \n\nSo why not try all nodes "as the center of star graph"\nFor each node,\n  **star graph = node itself(center node)  + all it\'s direct neighbors**\n  \n  Thus for each node treat it is as center node and **find sum of k highest value neighbors**\n  [Take care of negative values =>  exclude negative values as they would decrease overall sum]\n  \n  \n  \n```\nclass Solution {\npublic:\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) \n    {\n        int n = vals.size();\n        vector<vector<pair<int, int>>>adj(n);\n        for (vector<int>edge : edges)\n        {\n            int startNode = edge[0], startNodeVal = vals[startNode];\n            int endNode = edge[1], endNodeVal = vals[endNode];\n            adj[startNode].push_back({endNodeVal, endNode});\n            adj[endNode].push_back({startNodeVal, startNode});\n        }\n        //========================================================\n        int mxSum = INT_MIN;\n        for (int node = 0; node < n; node++)\n        {\n            sort(adj[node].begin(), adj[node].end()); //sort the neighbors based on increasing "values"\n            int neighborSize = adj[node].size();\n            int sum = vals[node];\n            for (int i = neighborSize - 1; i >= 0 && i >= (neighborSize - k); i--) //take k neighbors [start from largest vals]\n            {\n                int val = adj[node][i].first;\n                if (val < 0) break; //if value of neighbor is < 0, it would decrease sum so "break", \n\t\t\t\t                     //as the neighbors left to it would also have negative values\n                sum += val;\n            }\n            mxSum = max(mxSum, sum);\n        }\n        //=============================================================\n        return mxSum;\n        \n    }\n};\n```
['C', 'Sorting', 'C++']