Greedy approach
\n\n# Code\n\n#define ll long long\nclass Solution {\npublic:\n    long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {\n        ll
\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {\n        ll n = nums.size();\n        vector<int> g, l;\n        for(int i = 0 ; i < n ; i++){\n            int x = (nums[i] ^ k);\n            if(x > nums[i]){\n                g.push_back(x-nums[i]);\n            }\n            else{\n                l.push_back(nums[i]-x);\n            }\n        }\n        if(g.size() % 2 == 0){\n            ll ans = 0;\n            for(auto it : nums) ans += it;\n            for(auto it : g) ans += it;\n            return ans;\n        }\n        sort(g.begin(), g.end());\n        sort(l.begin(), l.end());\n        ll ans = 0;\n        for(auto it : nums) ans += it;\n        for(auto it : g) ans += it;\n        ans -= g[0];\n        ll ans2 = ans;\n        if(l.size() > 0){\n            ans2 = ans + g[0] - l[0];\n        }\n        return max(ans, ans2);\n    }\n};\n```
['C++']