using bfs and priority queue-easy understandable
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 {\npublic:\nvector<int>adj[100001];\nint vis[100001]={0};\nint  bfs(int node,vector<int>& val,int k)\n  {\n      queue<int>q;\n      q.push(node);\n      int maxm=INT_MIN;\n      while(!q.empty())\n      {\n        int temp=q.front();\n        q.pop();\n        int sum=0;\n        sum=val[temp];\n        if(vis[temp]==0)\n        {\n            priority_queue<int>pq;\n       for (auto child:adj[temp])\n        {\n            if(val[child]>0)\n          pq.push(val[child]);\n          q.push(child);\n        }\n        int j=k;\n        while(!pq.empty()&&pq.top()>0&&j>0)\n        {\n          sum+=pq.top();\n          pq.pop();\n          j--;\n        }\n        }\n        maxm=max(maxm,sum);\n        vis[temp]=1;\n      }\n      return maxm;\n  }\n    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {\n        int n=vals.size();\n        for(auto edge:edges)\n        {\n            adj[edge[0]].push_back(edge[1]);\n            adj[edge[1]].push_back(edge[0]);\n        }\n        int maxm=INT_MIN;\n      for(int i=0;i<n;i++)\n      {\n          if(vis[i]==0)\n          maxm=max(maxm,bfs(i,vals,k));\n      }\n      return maxm;\n    }\n};\n```
['Breadth-First Search', 'Heap (Priority Queue)', 'C++']