问题 D: Tree

内存限制:512 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

Given a tree of n vertices and �−1n1 edges. Each vertex i has a color ��ci = 'a' or 'b' or 'c'.

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

  • 1≤�≤�≤�1ijn
  • The number of vertices with three different colors is equal on the path.

输入格式

The first line contains one integer n (n105).

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

Each of the next n1 lines contains a pair of vertex indices ui and vi (1ui,vin)— endpoints of the corresponding edge.

输出格式

Output an integer represent the answer.

输入样例 复制

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

输出样例 复制

5