Easiest Solution Ever
\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\npython3 []\nclass Solution:\n    def maxStarSum(self, vals: List[int], edges: L
\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```python3 []\nclass Solution:\n    def maxStarSum(self, vals: List[int], edges: List[List[int]], k: int) -> int:\n        lst = defaultdict(list)\n        for e1,e2 in edges:\n            lst[e1].append(e2)\n            lst[e2].append(e1)\n        \n        max_ans=-math.inf\n        for node in range(len(vals)):\n            neighbours = lst[node]\n            vals_neigh = [vals[neighbour] for neighbour in neighbours if vals[neighbour]>0]\n            vals_neigh.sort(reverse=True)\n            vals_neigh=vals_neigh[:k]\n            ans=vals[node]+sum(vals_neigh)\n            max_ans=max(max_ans,ans)\n        return max_ans\n```
['Python3']