#ARC097D. [ARC097F] Monochrome Cat

[ARC097F] Monochrome Cat

Score : 800800 points

Problem Statement

There is a tree with NN vertices numbered 11 through NN. The ii-th edge connects Vertex xix_i and yiy_i. Each vertex is painted white or black. The initial color of Vertex ii is represented by a letter cic_i. cic_i == W represents the vertex is white; cic_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

  • 11 \leq NN \leq 10510^5
  • 11 \leq xi,yix_i,y_i \leq NN (11 \leq ii \leq N1N-1)
  • The given graph is a tree.
  • cic_i == W or cic_i == B.

Input

Input is given from Standard Input in the following format:

NN

x1x_1 y1y_1

x2x_2 y2y_2

::

xN1x_{N-1} yN1y_{N-1}

c1c2..cNc_1c_2..c_N

Output

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

5
1 2
2 3
2 4
4 5
WBBWW
5

The objective can be achieved in five seconds, for example, as follows:

  • Start at Vertex 11. Change the color of Vertex 11 to black.
  • Move to Vertex 22, then change the color of Vertex 22 to white.
  • Change the color of Vertex 22 to black.
  • Move to Vertex 44, then change the color of Vertex 44 to black.
  • Move to Vertex 55, then change the color of Vertex 55 to black.
6
3 1
4 5
2 6
6 1
3 4
WWBWBB
7
1
B
0
20
2 19
5 13
6 4
15 6
12 19
13 19
3 11
8 3
3 20
16 13
7 14
3 17
7 8
10 20
11 9
8 18
8 2
10 1
6 13
WBWBWBBWWWBBWWBBBBBW
21