#P9856. Tree

Tree

Tree

Problem Description

Given a tree of nn vertices and n1n-1 edges. Each vertex ii has a color cic_i = 'a' or 'b' or 'c'. Please count the number of simple path between ii and jj satisfy :

  • 1ijn1 \le i \le j \le n
  • The number of vertices with three different colors is equal on the path.

Input

The first line contains one integer nnn105 n \le 10^5 ). The second line contains a string S with length of nn . (SiS_i represents the color of ii-th vertex,Si= a or b or cS_i = \ 'a' \ or \ 'b' \ or \ 'c') Each of the next n1n-1 lines contains a pair of vertex indices uiu_i and viv_i1ui,vin1\le u_i,v_i \le n)— endpoints of the corresponding edge.

Output

Output an integer represent the answer.

Sample Input

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

Sample Output

5

Source

2023“钉耙编程”中国大学生算法设计超级联赛(6)