Python3, Sort Positive Neighbors
Approach\nWe are storing all positive neighbors for each node.\n\n# Complexity\n- Time complexity:\nO(Nlog(N))\n\n- Space complexity:\nO(N*2)\n\n# Code\n\nclass
# Approach\nWe are storing all positive neighbors for each node.\n\n# Complexity\n- Time complexity:\nO(N*log(N))\n\n- Space complexity:\nO(N**2)\n\n# Code\n```\nclass Solution:\n    def maxStarSum(self, vals: List[int], edges: List[List[int]], k: int) -> int:\n        if k==0: return max(vals) \n        n=len(vals)\n        answ=max(vals)\n        stars=[[] for _ in range(n)]\n        for a,b in edges:\n            if 0<vals[b]:\n                stars[a].append(vals[b])\n            if 0<vals[a]:\n                stars[b].append(vals[a])\n        answ=max(vals)\n        for i in range(n):\n            answ = max(answ,sum([vals[i]] + sorted(stars[i])[-k:]))  \n        return answ      \n```
['Python3']