priorityqueue one pass
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxStarSum(int[] vals, int[][] edges, int k) {\n        int res = Integer.MIN_VALUE, n = vals.length;\n        Pair<Integer,PriorityQueue<Integer>>[] graph = new Pair[n];\n        for(int i = 0; i < n; i++) {\n            res = Math.max(res, vals[i]);\n        }\n        \n        for(var e: edges) {\n            for(int x = 0; x < 2; x++) {\n                int a = e[0 ^ x], b = e[1 ^ x];\n                int bVal = vals[b];\n                if(bVal <= 0) continue;\n\n                var q = graph[a] == null ? new PriorityQueue<Integer>() : graph[a].getValue();\n                int sum = graph[a] == null ? vals[a] : graph[a].getKey();\n                q.add(bVal);\n                sum += bVal;\n                if(q.size() > k) {\n                    sum -= q.remove();\n                }\n                graph[a] = new Pair<>(sum, q);\n                res = Math.max(res, sum);\n            }\n        }\n        return res;\n    }\n}\n```
['Java']