C++ DFS UNION FIND
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxStarSum(vector<int>& vals, vector<vector<int>>& edges, int k) {
        int n = vals.size(), R = vals[0];
        map<int,vector<int>> ADJ;
        for (auto &edge : edges) {
            int from = edge[0], to = edge[1];
            ADJ[from].push_back(to);
            ADJ[to].push_back(from);
        }

        for (int i=0; i<n; ++i) {
            vector<int> neighbors = ADJ[i];
            vector<int> subvals;
            for (auto &ne : neighbors) {
                if (vals[ne]>0) subvals.push_back(vals[ne]);
            }
            sort(subvals.begin(),subvals.end());
            reverse(subvals.begin(),subvals.end());
            int sum = vals[i], kCopy = k;
            for (int j=0; j<subvals.size() && kCopy>0; ++j, --kCopy) sum += subvals[j];
            if (sum > R) R = sum;
        }
        return R;
    }
};
```
['C++']