Can XOR any two nodes
Intuition\nCan XOR any two nodes\n\n# Approach\nXOR elements in the path = XOR only first and last element in the path. So we don\'t even need edges, and we can
# Intuition\nCan XOR any two nodes\n\n# Approach\nXOR elements in the path = XOR only first and last element in the path. So we don\'t even need edges, and we can XOR any two nodes in the tree. \n\n\n# Complexity\n- Time complexity: O(n * log(n)), n = number of nodes\n\n- Space complexity: O(n) -> storing XOR values\n\n# Code\n```\nclass Solution:\n    def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n        for i in range(len(nums)):\n            nums[i] = [nums[i], nums[i] ^ k]\n        \n        nums.sort(key = lambda x: x[1] - x[0], reverse = True)\n\n        s = 0\n        j = 0\n        for i in range(1, len(nums), 2):\n            x = nums[i][1] + nums[i - 1][1]\n            y = nums[i][0] + nums[i - 1][0]\n            s += max(x, y)\n            j = i + 1\n\n        for i in range(j, len(nums)):\n            s += nums[i][0]\n\n        return s\n```
['Python3']