scala solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nobject Solution {\n  def maximumValueSum(nums: Array[Int], k: Int, edges: Array[Array[Int]]): Long = {\n    val res = nums.foldLeft(0L, Integer.MAX_VALUE, 0)((acc, num) => {\n      val temp = num ^ k\n      (acc._1 + Math.max(num, temp), acc._2.min(Math.abs(num - temp)), acc._3 ^ (if((num < temp)) 1 else 0))\n    })\n    res._1 - res._2 * res._3\n  }\n}\n```
['Scala']