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?

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - 1 ≤ x_i,y_i ≤ N (1 ≤ i ≤ N-1)
 - The given graph is a tree.
 - c_i = W or c_i = B.

-----Input-----
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

-----Output-----
Print the minimum number of seconds required to achieve the objective.

-----Sample Input-----
5
1 2
2 3
2 4
4 5
WBBWW

-----Sample Output-----
5

The objective can be achieved in five seconds, for example, as follows:
 - Start at Vertex 1. Change the color of Vertex 1 to black.
 - Move to Vertex 2, then change the color of Vertex 2 to white.
 - Change the color of Vertex 2 to black.
 - Move to Vertex 4, then change the color of Vertex 4 to black.
 - Move to Vertex 5, then change the color of Vertex 5 to black.

Difficulty: VERY_HARD

Solutions:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
data = read().split()
m = map(int, data[:-1])
XY = zip(m, m)
C = [0] + [1 * (x == ord('W')) for x in data[-1]]
graph = [set() for _ in range(N + 1)]
for (x, y) in XY:
	graph[x].add(y)
	graph[y].add(x)
deg = [len(x) for x in graph]
b_leaf = [i for i in range(N + 1) if deg[i] == 1 and (not C[i])]
while b_leaf:
	x = b_leaf.pop()
	for y in graph[x]:
		graph[y].remove(x)
		deg[y] -= 1
		if deg[y] == 1 and (not C[y]):
			b_leaf.append(y)
	deg[x] = 0
	graph[x].clear()
V = set((i for (i, E) in enumerate(graph) if E))
if len(V) <= 2:
	print(sum(C))
	exit()
root = None
for v in V:
	if deg[v] > 1:
		root = v
		break
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
for i in range(N + 1):
	C[i] ^= 1 & deg[i]
cost_full = sum(deg) + sum(C)
opt = 0
dp = [0] * (N + 1)
for v in order[::-1]:
	if deg[v] == 1:
		continue
	arr = sorted((dp[w] for w in graph[v] if w != parent[v]), reverse=True) + [0]
	x = arr[0] + arr[1] + C[v]
	if opt < x:
		opt = x
	dp[v] = arr[0] + C[v]
answer = cost_full - 2 * opt
print(answer)