[Java] | ✅Adjacency List Graph | PriorityQueue | TopK | Easy to Understand | 50ms🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nFor each node, we need it\'s own value (can be negative) and it\'s top k neighbor with 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor each node, we need it\'s own value (can be negative) and it\'s top k neighbor with positive values .\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreate the adjacency list graph first, and loop each node to get max start sum.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(V+E)\ncreate and iterate over graph\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(V+E+k)\nV+E to create graph\nk size priority queue\n\n# Code\n[50ms Submission](https://leetcode.com/problems/maximum-star-sum-of-a-graph/submissions/857816006/)\n```java\nclass Solution {\n    public int maxStarSum(int[] vals, int[][] edges, int k) {\n        int res = vals[0];\n        if (k == 0) { // corner case\n            for (var x : vals) res = Math.max(res, x);\n            return res;\n        }\n\n        // create graph\n        int n = vals.length;\n        List<Integer>[] g = new List[n];\n        for (int i = 0; i < n; i++) g[i] = new ArrayList<>();\n        for (var e : edges) {\n            if (vals[e[1]] > 0) g[e[0]].add(vals[e[1]]);\n            if (vals[e[0]] > 0) g[e[1]].add(vals[e[0]]);\n        }\n\n        for (int i = 0; i < n; i++) res = Math.max(res, topK(g[i], vals[i], k));\n        return res;\n    }\n\n    private int topK(List<Integer> l, int res, int k) {\n        Queue<Integer> q = new PriorityQueue<>();\n        for (int x : l) {\n            if (q.size() < k) q.offer(x);\n            else if (x > q.peek()) {\n                q.poll();\n                q.offer(x);\n            }\n        }\n\n        while (!q.isEmpty()) res += q.poll();\n\n        return res;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']