Codeforces Round 333 (Div. 1)
D
Acyclic Organic Compounds
Codeforces
2400
原题
← CE →
翻译中…

You are given a tree $*T*$ with $*n*$ vertices (numbered $1$ through $*n*$) and a letter in each vertex. The tree is rooted at vertex $1$.

翻译中…

Let's look at the subtree $*T*_{*v*}$ of some vertex $*v*$. It is possible to read a string along each simple path starting at $*v*$ and ending at some vertex in $*T*_{*v*}$ (possibly $*v*$ itself). Let's denote the number of distinct strings which can be read this way as image.

翻译中…

Also, there's a number $*c*_{*v*}$ assigned to each vertex $*v*$. We are interested in vertices with the maximum value of image.

翻译中…

You should compute two statistics: the maximum value of image and the number of vertices $*v*$ with the maximum image.

翻译中…

Input

翻译中…

The first line of the input contains one integer $*n*$ ($1 ≤ *n* ≤ 300 000$) — the number of vertices of the tree.

翻译中…

The second line contains $*n*$ space-separated integers $*c*_{*i*}$ ($0 ≤ *c*_{*i*} ≤ 10^{9}$).

翻译中…

The third line contains a string $*s*$ consisting of $*n*$ lowercase English letters — the $*i*$-th character of this string is the letter in vertex $*i*$.

翻译中…

The following $*n* - 1$ lines describe the tree $*T*$. Each of them contains two space-separated integers $*u*$ and $*v*$ ($1 ≤ *u*, *v* ≤ *n*$) indicating an edge between vertices $*u*$ and $*v*$.

翻译中…

It's guaranteed that the input will describe a tree.

翻译中…

Output

翻译中…

Print two lines.

翻译中…

On the first line, print image over all $1 ≤ *i* ≤ *n*$.

翻译中…

On the second line, print the number of vertices $*v*$ for which image.

翻译中…

Note

翻译中…

In the first sample, the tree looks like this:

翻译中…

image

翻译中…

The sets of strings that can be read from individual vertices are:

翻译中…

image

翻译中…

Finally, the values of image are:

翻译中…

image

翻译中…

In the second sample, the values of image are $(5, 4, 2, 1, 1, 1)$. The distinct strings read in $*T*_{2}$ are image; note that image can be read down to vertices $3$ or $4$.

翻译中…

样例

Input #1
10
1 2 7 20 20 30 40 50 50 50
cacabbcddd
1 2
6 8
7 2
6 2
5 4
5 9
3 10
2 5
2 3
Output #1
51
3
InputCopy OutputCopy
Input #2
6
0 2 4 1 1 1
raaaba
1 2
2 3
2 4
2 5
3 6
Output #2
6
2
InputCopy OutputCopy
题目信息
题号
601D
时间限制
3 s
内存限制
512 MB
标签
数据结构
DFS 及类似
并查集
哈希
字符串
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。