Reina is interested in colourful trees. In particular, she currently has her eyes on a tree with
Constraints
In all subtasks,
Subtask 1 [10%]
Subtask 2 [20%]
The degree of each node is at most
Subtask 3 [30%]
Subtask 4 [40%]
No additional constraints.
Input Specification
The first line contains one integer,
The next line contains a string with R
if node B
if it is blue.
Note: the nodes are
Output Specification
The number of subgraphs of the given tree that form trees where all its leaves are the same colour modulo
Sample Input 1
6
BBRRRB
5 4
1 6
2 1
5 2
1 3
Sample Output 1
12
Explanation for Sample Output 1
There are 12 subgraphs with same coloured leaves.
Sample Input 2
5
BBBRB
5 3
3 2
5 1
5 4
Sample Output 2
11
Comments
I really don't understand sample 1, can anyone explain it please?
For sample 1, the vertices of the valid subgraphs are
(Red Leaves)
(Blue Leaves)
Thank you!