Java solution using sorting
Intuition\nstore the  value  of a node connected to a star node  in a list in descending order and add  k elements from the list,do for every n nodes.\n\n# Appr
# Intuition\nstore the  value  of a node connected to a star node  in a list in descending order and add  k elements from the list,do for every n nodes.\n\n# Approach\nGraph traversal\n\n# Complexity\n- Time complexity:\nO(N*LogN)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\n    public int maxStarSum(int[] vals, int[][] edges, int k) {\n        ArrayList<ArrayList<Integer>> list=new ArrayList();\n        int arr[]=new int[vals.length];\n        for(int i=0;i<vals.length;i++)\n            arr[i]=vals[i];\n//edge cases\n        if(vals.length==1)\n            return vals[0];\n        \n        int n=vals.length;\n        for(int i=0;i<=n;i++){\n            list.add(new ArrayList<Integer>());\n        }\n        for(int row[]:edges){\n            list.get(row[0]).add(row[1]);\n            list.get(row[1]).add(row[0]);\n        }\n//edge cases\n        Arrays.sort(vals);\n        if(edges.length==0)\n            return vals[vals.length-1];\n        int max=0;\n        \n        for(int i=0;i<n;i++){\n            List<Integer> adj=list.get(i);\n            List<Integer> temp=new ArrayList<Integer>();\n            for(int it:adj){\n                temp.add(arr[it]);\n            }\n           Collections.sort(temp, Collections.reverseOrder());\n            int sum=arr[i];\n            max=Math.max(sum,max);\n            int s=k;\n            for(int it:temp){\n                sum+=it;\n                max=Math.max(sum,max);\n                s--;\n                if(s==0)\n                    break;\n            }\n            \n            \n         \n        }\n        return max;\n        \n        \n    }\n}\n```
['Java']