O(n) || Greedy || Very easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \nThe main intuition lies in the fact there is nothing to do with edges because it is com
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe main intuition lies in the fact there is nothing to do with edges because it is completely connected graph we can take any 2 nodes to do xor operation for suppose my tree is \na->b->c then for doing xor between a and c we have to do with (a , b) and then (b,c) since b was involved twice b^k^k = b \n    \n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf we are performing xor operation for 2 nodes at a time then time complexity will be o(n^2) so somehow we have to come up with a approach where we don\'t care about second node and can do xor operation for each node , Take an example of tree a->b->c->d \nall the possible trees after doing xor operations are\n\n1) a\'->b\'->c->d (Note :- a\' = a^k)\n2) a\'->b->c\'->d\n3) a\'->b->c->d\'\n4) a->b\'->c\'->d\n5) a->b\'->c->d\'\n6) a->b->c\'->d\'\n7) a\'->b\'>c\'->d\'\n\nWe can observe that in all the possible outcomes number of nodes where xor operation is performed is always even .\n\nSo traverse all the nodes store sum of max(a , a\')\n\nIf we perform an XOR operation on an odd number of nodes, we have two choices: either we skip the XOR operation on one of the nodes where we would normally perform it, or we perform the XOR operation on a node where we wouldn\'t normally do so. Either way, this adjustment will result in the number of nodes where XOR is performed being even.\n\nSo store min difference\'s of a\'-a where we performed XOR and a-a\' where we didn\'t perform XOR subract the minumum of those if the count is odd \n\n\nNote :- If it is not fully connected graph then we can\'t follow this approach .\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: o(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {\n        int n = nums.size() ; \n        long long ans = 0 ; \n        int xor_d = 1e9 ; // The min difference we have to sacrifice without doing xor operation\n        int nxor_d = 1e9 ; // The min difference we have to sacrifice by doing xor .\n        int cnt = 0 ; // No of elements where xor val is greater than node val\n        for(int i = 0 ; i < n ; i++){\n            int xor_val = nums[i]^k ;\n            if(xor_val > nums[i]){\n                cnt++;\n                ans += xor_val ; \n                xor_d = min(xor_d , xor_val - nums[i]);\n            }else{\n                ans += nums[i] ;\n                nxor_d = min(nxor_d , nums[i]-xor_val) ; \n            }\n        }\n        if(cnt%2 == 0){\n            return ans ;\n        }\n        return ans - min(xor_d , nxor_d) ;\n    }\n};\n```
['Greedy', 'Bit Manipulation', 'C++']