:: Kotlin :: Don't be distracted from the tree!
\'edges\' is just a macguffin.\n\nAll information needed from the tree structure is\nThis means that an even number of xor operations can be performed.\n\n# Cod
# \'edges\' is just a macguffin.\n\nAll information needed from the tree structure is\nThis means that an even number of xor operations can be performed.\n\n# Code\n```\nclass Solution {\n    fun maximumValueSum(nums: IntArray, k: Int, edges: Array<IntArray>): Long {\n        var result = nums.map{it.toLong()}.sum()!!\n        val n = nums.size\n        var xors = Array(n){ intArrayOf(nums[it], nums[it] xor k) }\n\n        val list = xors.sortedWith(compareBy({ it[0] - it[1] }))\n\n        for (i in 1 until n step 2) {\n            val temp = result - list[i][0] - list[i - 1][0] + list[i][1] + list[i - 1][1]\n            if (temp < result) break\n            result = temp\n        }\n\n        return result\n    }\n}\n```
['Kotlin']