Simplified C# Explanation with comments | Lists
Intuition\nWe need to find max sum of subgraph (star graph) with atmost k connected edges.\nSo, we need to create a adj list for each node, then calculate max s
# Intuition\nWe need to find max sum of subgraph (star graph) with atmost k connected edges.\nSo, we need to create a adj list for each node, then calculate max sum of atmost k connected edges.\n\n# Approach\n1. Handle edge case where if k = 0, return max node as we will not consider any edges.\n2. Initialize adjacency list (stars) which a list of list of int i.e. list of all the nodes and their correcponding edges:\n- This ensures, node x contains all the positive neighbour values for x.\n- Since its an undirected graph, from and/or to are not much important. If any/both of these are positive, we consider.\n3. Iterate through each node to calculate its max star sum:\n- Create a list of top k edges (of that node) in descending order of their value.\n- Sum the current node\'s value with the sum of all the k edges obtainede in the previous line.\n- Update the max ans accordingly.\n\n# Complexity\n- Time complexity:\nO(N + KLogK): N for single for loops + K.LogK for finding top k edges on each iteration.\n\n- Space complexity:\nO(N): Additional list is required.\n\n# Code\n```csharp []\npublic class Solution {\n    public int MaxStarSum(int[] vals, int[][] edges, int k) {\n        if(k == 0)\n            return vals.Max();\n\n        List<List<int>> stars = new();\n        for(int i = 0; i < vals.Length; i++)\n        {\n            stars.Add(new List<int>());\n        }\n\n        // Build adjacency list for each star:\n        int from, to;\n        for(int i = 0; i < edges.Length; i++)\n        {\n            from = edges[i][0];\n            to = edges[i][1];\n\n            if(vals[to] > 0)\n                stars[from].Add(vals[to]);\n            if(vals[from] > 0)\n                stars[to].Add(vals[from]);\n        }\n\n        //Init ans as max node value\n        int ans = vals.Max();\n\n        // Iterate through each node to calculate max star sum\n        List<int> topNeighbors;\n        for(int i = 0; i < vals.Length; i++)\n        {\n            topNeighbors = stars[i].OrderByDescending(x => x).Take(k).ToList();\n\n            // Sum the node\'s value and its k highest positive numbers\n            ans = Math.Max(ans, vals[i] + topNeighbors.Sum());\n        }\n\n        return ans;\n    }\n}\n```
['Array', 'Graph', 'Sorting', 'C#']