Easiest logical implementation | without DP or Tree
Intuition\nWe have to find the max sum we can achieve by doing xor of element and k.\n# Approach\n- Lets update each element whose value increases after xor wit
# Intuition\nWe have to find the max sum we can achieve by doing xor of element and k.\n# Approach\n- Lets update each element whose value increases after xor with k.\n- Also track the count of number of elements updated with xor -- cnt variable.\n- The problem says that we have to take two nodes which are connected(elements given in nums) and then xor them. \n- So, for the case where xor is not done in pair means if cnt is odd(cnt&1) -- check the parity bit, we have to go through the updated nums array and find the element which was update by least value and then subract it from the sum.\n\nProblem Solved!\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    #define ll long long\n    long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {\n        ll sum=0,cnt=0;\n        for(auto &i:nums){\n            if((i^k)>i) cnt++,i^=k;\n            sum+=i;\n        }\n        if(cnt&1){\n            int mn=1e9;\n            for(auto i:nums) mn=min(mn,i-(i^k));\n            sum-=mn;\n        }\n        return sum;\n    }\n};\n```
['C++']