#P9856. Tree
Tree
Tree
Problem Description
Given a tree of vertices and edges. Each vertex has a color = 'a' or 'b' or 'c'. Please count the number of simple path between and satisfy :
- The number of vertices with three different colors is equal on the path.
Input
The first line contains one integer (). The second line contains a string S with length of . ( represents the color of -th vertex,) Each of the next lines contains a pair of vertex indices and ()— 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)