✅ [Python] take largest positive weights (explained)
\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\n\n*Comment. Take at most k largest positive weights for each node.\n\nPython #1. Compact version.\n\nclass 
**\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\n\n**Comment.** Take at most `k` largest positive weights for each node.\n\n**Python #1.** Compact version.\n```\nclass Solution:\n    def maxStarSum(self, v: List[int], edges: List[List[int]], k: int) -> int:\n        \n        g = defaultdict(set)\n        for i,j in edges:\n            if v[i] > 0 : g[j].add(i)\n            if v[j] > 0 : g[i].add(j)\n                \n        return max(w + sum(sorted([v[j] for j in g[i]], reverse=True)[0:k])\n                   for i,w in enumerate(v))\n```\n\n**Python #2.** A more detailed solution.\n```\nclass Solution:\n    def maxStarSum(self, vals: List[int], edges: List[List[int]], k: int) -> int:\n        \n        graph = defaultdict(set)\n        for i,j in edges:\n            if vals[i] > 0 : graph[j].add(i)\n            if vals[j] > 0 : graph[i].add(j)\n            \n        stars = []\n        for i,v in enumerate(vals):\n            vv = [vals[j] for j in graph[i]]\n            vv.sort(reverse=True)\n            stars.append(v + sum(vv[0:k]))\n            \n        return max(stars)\n```
[]