2497. Maximum Star Sum of a Graph
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def maxStarSum(self, vals: List[int], edges: List[List[int]], k: int) -> int:
        n = len(vals)
        adj = defaultdict(list)
        for u, v in edges:
            adj[u].append(v)
            adj[v].append(u)

        max_sum = max(vals)
        
        for i in range(n):
            neighbors = []
            for neighbor in adj[i]:
                if vals[neighbor] > 0:
                    neighbors.append(vals[neighbor])
            neighbors.sort(reverse=True)
            
            total_sum = vals[i]
            for j in range(min(k, len(neighbors))):
                total_sum += neighbors[j]
            
            max_sum = max(max_sum, total_sum)
        
        return max_sum

```
['Python3']