Fastest Solution
Code\n\n// sample 116 ms submission\nstatic auto speedup = []() { std::ios_base::sync_with_stdio(false); std::cout.tie(nullptr); std::cin.tie(nullptr); return N
# Code\n```\n// sample 116 ms submission\nstatic auto speedup = []() { std::ios_base::sync_with_stdio(false); std::cout.tie(nullptr); std::cin.tie(nullptr); return NULL; }();\nclass Solution\n{\npublic:\n    long long maximumValueSum(vector<int> &nums, int k, vector<vector<int>> &edges)\n    {\n        long long cnt = 0;\n        long long res = 0;\n        long long minn = INT_MAX;\n        long long maxx = INT_MAX;\n\n        for(long long i : nums)\n        {\n            long long x = i;\n            long long y = i ^ k;\n\n            if(x > y)\n            {\n                res += x;\n                maxx = min(maxx, x);\n            }\n            else\n            {\n                res += y;\n                ++cnt;\n            }\n\n            minn = min(minn, abs(x - y));\n        }\n\n        if(cnt & 1)\n        {\n            res -= minn;\n        }\n\n        return res;\n    }\n};\n```
['C++']