Find the Maximum Sum of Node Values
Intuition\n \n# Approach\n\n# Complexity\n- Time complexity:\n\n- Space complexity:\n\n\n# Code\n\nclass Solution {\npublic:\n    long long maximumValueSum(vect
# Intuition\n \n# Approach\n\n# Complexity\n- Time complexity:\n\n- Space complexity:\n\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {\n        long long totalSum = 0;\n        int count = 0;\n        int positiveMin = INT_MAX;\n        int negativeMax = INT_MIN;\n\n        for (int nodeValue : nums) {\n            int nodeValAfterOperation = nodeValue ^ k;\n            totalSum += nodeValue;\n            int netChange = nodeValAfterOperation - nodeValue;\n\n            if (netChange > 0) {\n                positiveMin = min(positiveMin, netChange);\n                totalSum += netChange;\n                count += 1;\n            } else {\n                negativeMax = max(negativeMax, netChange);\n            }\n        }\n\n        if (count % 2 == 0) {\n            return totalSum;\n        }\n        return max(totalSum - positiveMin, totalSum + negativeMax);  \n    }\n};\n```
['C++']