Python3 Solution
\n\nclass Solution:\n    def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n        ans=0\n        c=0\n        d=1<<30\n      
\n```\nclass Solution:\n    def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n        ans=0\n        c=0\n        d=1<<30\n        for num in nums:\n            ans+=max(num, num1:=num^k)\n            c^=num<num1\n            d=min(d,abs(num-num1))\n        return ans-d*c    \n```
['Python', 'Python3']