input: from typing import List
  from math import inf
  
  def calculate_maximum_sum_of_node_values(nums: List[int], k: int, edges: List[List[int]]) -> int:
      """
      Consider an undirected tree with n nodes labeled from 0 to n - 1. You have a 0-indexed 2D integer list edges of size n - 1, where edges[i] = [u_i, v_i] represents an edge between nodes u_i and v_i. You also have a positive integer k, and a 0-indexed list of non-negative integers nums of length n, where nums[i] indicates the value of node i.
  
      Alice aims to maximize the sum of the node values in the tree by executing the following operation multiple times (including none): 
  
      Select an edge [u, v] connecting nodes u and v, and modify their values as follows:
      nums[u] = nums[u] XOR k
      nums[v] = nums[v] XOR k
      Return the greatest possible sum of values Alice can obtain by applying the operation any number of times.
  
      Examples:
      >>> nums = [1,2,1], k = 3, edges = [[0,1],[0,2]]
      6
      >>> nums = [2,3], k = 7, edges = [[0,1]]
      9
      >>> nums = [7,7,7,7,7,7], k = 3, edges = [[0,1],[0,2],[0,3],[0,4],[0,5]]
      42
  
      Constraints:
      2 <= n == nums.length <= 2 * 10^4
      1 <= k <= 10^9
      0 <= nums[i] <= 10^9
      edges.length == n - 1
      edges[i].length == 2
      0 <= edges[i][0], edges[i][1] <= n - 1
      The input is generated such that edges form a valid tree.
      """
output:     
      original_sum = sum(nums)
      max_xor_sum = 0
  
      for num in nums:
          max_xor_sum += max(num, num ^ k)
  
      return max(original_sum, max_xor_sum)
  