[Java] Simple Graph solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nSort the neighbour nodes based on their weights and take k biggest values
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSort the neighbour nodes based on their weights and take **k** biggest values\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(NMlogM), M - max edge number\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\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 n = vals.length;\n        List<Integer>[] graph = new List[n];\n        \n        for (int i = 0; i < n; i++) {\n            graph[i] = new ArrayList<Integer>();\n        }\n        \n        for (int[] edge : edges) {\n            int a = edge[0], b = edge[1];\n            graph[a].add(b);\n            graph[b].add(a);\n        }\n        \n        long res = Long.MIN_VALUE;\n        \n        for (int i = 0; i < n; i++) {\n            List<Integer> curr = graph[i];\n            \n            curr.sort((a, b) -> vals[b]-vals[a]);\n            \n            long max = vals[i], sum = vals[i];\n            \n            for (int j = 0; j < k && j < curr.size(); j++) {\n                sum += vals[curr.get(j)];\n                max = Math.max(max, sum);\n            }\n            \n            res = Math.max(res, max);\n        }\n        \n        return (int) res;\n    }\n}\n```
['Java']