Python solution with n in time and 1 in space
Complexity\n- Time complexity:\nO(n) \n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution:\n  def maximumValueSum(self, nums, k, edges):\n    maxSum = sum(
# Complexity\n- Time complexity:\n$$O(n)$$ \n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n  def maximumValueSum(self, nums, k, edges):\n    maxSum = sum(max(num, num ^ k) for num in nums)\n    changedCount = sum((num ^ k) > num for num in nums)\n    if changedCount % 2 == 0:\n      return maxSum\n    minChangeDiff = min(abs(num - (num ^ k)) for num in nums)\n    return maxSum - minChangeDiff\n```
['Python']