AtCoder Regular Contest 097
F
Monochrome Cat
AtCoder
⌀ 2948
原题
← E→
翻译中…

Problem 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?

翻译中…

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.

翻译中…

样例

Input #1
5
1 2
2 3
2 4
4 5
WBBWW
Output #1
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.
Input #2
6
3 1
4 5
2 6
6 1
3 4
WWBWBB
Output #2
7
Input #3
1
B
Output #3
0
Input #4
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
Output #4
21
题目信息
题号
arc097_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。