图片被删除,或者路径改变
问题1427--Tree(6)

1427: Tree(6)

[命题人 : ]
时间限制 : 4.000 sec  内存限制 : 512 MiB

题目描述

Given a tree of $n$ vertices and $n-1$ edges. Each vertex $i$ has a color $c_i$ = 'a' or 'b' or 'c'.

Please count the number of simple path between $i$ and $j$ satisfy :

* $1 \le i \le j \le n$

* The number of vertices with three different colors is equal on the path.

输入

The first line contains one integer $n$ ($ n \le 10^5 $).

The second line contains a string S with length of $n$ . ($S_i$ represents the color of $i$-th vertex,$S_i = \ 'a' \ or \ 'b' \ or \ 'c'$)

Each of the next $n-1$ lines contains a pair of vertex indices $u_i$ and $v_i$ ($1\le u_i,v_i \le n$)— endpoints of the corresponding edge.

输出

Output an integer represent the answer.

样例输入 Copy

6
abbccb
1 2
1 3
1 4
1 5
4 6

样例输出 Copy

5