output_description: Print the minimum number of seconds required to achieve the objective.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      x_1 y_1
      x_2 y_2
      :
      x_{N-1} y_{N-1}
      c_1c_2..c_N
attempt: input = __import__("sys").stdin.readline
  MIS = lambda: map(int, input().split())
  
  n = int(input())
  adj = [set() for i in range(n + 1)]
  white = [False]
  for i in range(n - 1):
      a, b = MIS()
      adj[a].add(b)
      adj[b].add(a)
  s = input().rstrip()
  for i in range(n):
      white.append(s[i] == "W")
  
  # Corner cases
  if sum(white) <= 1:
      print(sum(white))
      exit()
  
  # Remove black leaves
  stack = [i for i in range(1, n + 1) if len(adj[i]) == 1 and not white[i]]
  while stack:
      p = stack.pop()
      pa = min(adj[p])
      adj[pa].remove(p)
      adj[p].clear()
      if len(adj[pa]) == 1 and not white[pa]:
          stack.append(pa)
  
  # Simulate Euler tour
  root = 1
  while not adj[root]:
      root += 1
  tadj = [[] for i in range(n + 1)]
  vis = [False] * (n + 1)
  vis[root] = True
  stack = [root]
  while stack:
      p = stack.pop()
      for q in adj[p]:
          if vis[q]:
              continue
          vis[q] = True
          tadj[p].append(q)
          stack.append(q)
  for i in range(1, n + 1):
      if adj[i] and len(tadj[i]) % 2 == 0:
          white[i] = not white[i]
  white[root] = not white[root]
  
  
  # Diameter
  def bfs(v):
      stack = [v]
      dist = [-1] * (n + 1)
      dist[v] = white[v]
      while stack:
          p = stack.pop()
          for q in adj[p]:
              if dist[q] != -1:
                  continue
              dist[q] = dist[p] + white[q]
              stack.append(q)
      return dist
  
  
  numedge = sum(map(len, adj))
  d1 = bfs(root)
  u = d1.index(max(d1))
  d2 = bfs(u)
  diam = max(d2)
  print(numedge - diam)
  
problem_description: Statement
  
  There is a tree with N vertices numbered 1 through N. The i-th edge connects
  Vertex x_i and y_i. Each vertex is painted white or black. The initial color
  of Vertex i is represented by a letter c_i. c_i = `W` represents the vertex is
  white; c_i = `B` represents the vertex is black.
  
  A cat will walk along this tree. More specifically, she performs one of the
  following in one second repeatedly:
  
    * Choose a vertex that is adjacent to the vertex where she is currently, and move to that vertex. Then, invert the color of the destination vertex.
    * Invert the color of the vertex where she is currently.
  
  The cat's objective is to paint all the vertices black. She may start and end
  performing actions at any vertex. At least how many seconds does it takes for
  the cat to achieve her objective?
samples: [{"input": "5\n    1 2\n    2 3\n    2 4\n    4 5\n    WBBWW", "output": "5\n    \n\nThe objective can be achieved in five seconds, for example, as follows:\n\n  * Start at Vertex 1. Change the color of Vertex 1 to black.\n  * Move to Vertex 2, then change the color of Vertex 2 to white.\n  * Change the color of Vertex 2 to black.\n  * Move to Vertex 4, then change the color of Vertex 4 to black.\n  * Move to Vertex 5, then change the color of Vertex 5 to black.\n\n* * *"}, {"input": "6\n    3 1\n    4 5\n    2 6\n    6 1\n    3 4\n    WWBWBB", "output": "7\n    \n\n* * *"}, {"input": "1\n    B", "output": "0\n    \n\n* * *"}, {"input": "20\n    2 19\n    5 13\n    6 4\n    15 6\n    12 19\n    13 19\n    3 11\n    8 3\n    3 20\n    16 13\n    7 14\n    3 17\n    7 8\n    10 20\n    11 9\n    8 18\n    8 2\n    10 1\n    6 13\n    WBWBWBBWWWBBWWBBBBBW", "output": "21"}]