JAVA || Adjacency List || Priority Queue
Idea is to create a adjacency list from the edges array given\n2. I have take Priority Queue  for storing the edges as it will give us the maximum node values a
1. Idea is to create a adjacency list from the edges array given\n2. I have take Priority Queue  for storing the edges as it will give us the maximum node values at top.\n3. Do consider the key as the mandatory part of the star graph sum.\n```\nclass Solution {\n    public int maxStarSum(int[] vals, int[][] edges, int k) {\n        HashMap<Integer, PriorityQueue<Integer>> hm = new HashMap<>();\n        \n\t\t// edge cases\n        if(vals.length ==1)\n        {\n            return vals[0];\n        }\n        int min = Integer.MIN_VALUE;\n        if(edges.length == 0)\n        {\n            for(int i=0;i<vals.length;i++)\n            {\n                min = Math.max(min, vals[i]);\n            }\n            \n            return min;\n        }\n        \n        for(int i=0;i<edges.length;i++)\n        {\n            int x = edges[i][0];\n            int y = edges[i][1];\n            \n            if(hm.containsKey(x))\n            {\n                PriorityQueue<Integer> pq = hm.get(x);\n                pq.add(vals[y]);\n                hm.put(x, pq);\n            }\n            else\n            {\n\t\t\t\t// take max heap\n                PriorityQueue<Integer> maxPQ = new PriorityQueue<>(Collections.reverseOrder());\n                maxPQ.add(vals[y]);\n                hm.put(x, maxPQ);\n            }\n            \n            if(hm.containsKey(y))\n            {\n                PriorityQueue<Integer> pq = hm.get(y);\n                pq.add(vals[x]);\n                hm.put(y, pq);\n            }\n            else\n            {\n\t\t\t\t// take max heap\n                PriorityQueue<Integer> maxPQ = new PriorityQueue<>(Collections.reverseOrder());\n                maxPQ.add(vals[x]);\n                hm.put(y, maxPQ);\n            }\n        }\n        \n        int maxVal = Integer.MIN_VALUE;\n        for (Map.Entry<Integer, PriorityQueue<Integer>> entry : hm.entrySet())\n        {  \n            //returns keys and values respectively  \n            int key = entry.getKey();\n            PriorityQueue<Integer> pq = entry.getValue(); \n            int num = k;\n            int sum = vals[key];     //key must be a part of star \n            while(pq.size()>0 && num>0)\n            {\n                int val = pq.poll();\n               \n                if(sum+val<sum)\n                {\n                    break;\n                }\n                else\n                {\n                    sum = sum+val;\n                    num--;\n                }\n            }\n            maxVal = Math.max(maxVal, sum);\n        } \n        return maxVal == Integer.MIN_VALUE ? 0 : maxVal;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']