Simple solution with linear time complexity and constant extra space complexity
Intuition\n\nFirst of, let\'s think about situation when the operation was applied two time for the same edge, or in particular, to the same vertex. As of verte
# Intuition\n\nFirst of, let\'s think about situation when the operation was applied two time for the same edge, or in particular, to the same vertex. As of vertex, the second operation reverts the first one since `(nums[u] XOR k) XOR k == nums[u]`. Two conclusions out of this:\n\n1. we may consider at most one operation on particular edge without losing commonality\n2. the order of operations doesn\'t matter, and the value of specific vertex is determined by parity of the number of edges from that vertex for which we applied operation.\n\nIn other words, each number in `nums` would either stay the same, or be `XOR`ed.\n\nThen, let\'s figure out which subsets of `nums` could be `XOR`ed. Obviously, subset should contain even number of elements.\n\nCan any pair of elements be `XOR`ed (while the rest are the same)?\nYes, for any pair `(u, v)` there is path `u -> u_1 -> ... -> u_m -> v`. After applying operations to every edge on this path the value of `u` and `v` would be `XOR`ed, while the value of every `u_i` would be the same (formally, for every `u_i` there is exactly two operations, so the value would be the same).\n\nOk, any pair could be `XOR`ed. Can any subset consisting of even number of elements be `XOR`ed (while the rest are the same)? Well, yes. We just split such subset into pairs (we can do it since subset contains even number of elements) and then do the steps described above. NB: it doesn\'t matter whether these paths are crossing, share some edges, or even if one path is subpath of another. this is because for every intermediate vertex the operation is applied two times, so it doesn\'t change its value.\n\n# Approach\n\nAs explained above, we need to consider all subsets consisting of even elements, apply `XOR k` to every element, and find maximum sum of elements.\n\nLet\'s use dynamic programming for such purposes.\n\nSo, we need to remember just two numbers:\n\n1. `a` \u2014 maximum sum of elements if even number of elements were `XOR`ed\n2. `b` \u2014 maximum sum of elements if odd number of elements were `XOR`ed\n\nInitially, `a = nums[0]` and `b = nums[0] XOR k`. Then, we add `nums[1]`, `nums[2]`, etc.\n\nEvery step the new number is either stays the same, or is `XOR`ed.\n\n- `new_a = max(a + num, b + num XOR k)`\n- `new_b = max(a + num XOR k, b + num)`\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nfunc maximumValueSum(nums []int, k int, edges [][]int) int64 {\n    a, b := int64(nums[0]), int64(nums[0] ^ k)\n    for _, num := range nums[1:] {\n        a, b = max(a + int64(num), b + int64(num ^ k)), max(a + int64(num ^ k), b + int64(num))\n    }\n    return a\n}\n\nfunc max(a, b int64) int64 {\n    if b > a {\n        return b\n    }\n    return a\n}\n```
['Dynamic Programming', 'Go']