Problem F. Acyclic Organic Compounds

时间限制 3000 ms   内存限制 512 MB

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 Tv of some vertex v. It is possible to read a string along each simple path starting at v and ending at some vertex in Tv (possibly v itself). Let's denote the number of distinct strings which can be read this way as .

Also, there's a number cv assigned to each vertex v. We are interested in vertices with the maximum value of .

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

输入数据

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 ci (0 ≤ ci ≤ 109).

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.

输出数据

Print two lines.

On the first line, print b65ab1435108f6e44e5dc462a4f21c198e702433.png over all 1 ≤ i ≤ n.

On the second line, print the number of vertices v for which cff5eb8ec856ac7d3c5e12d61b8f169e9556d3df.png.

样例

样例说明

In the first sample, the tree looks like this:

7975a6972576c720a1c31d97b2e5d868c2fe77a7.png

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

be620298431b37ceeae5a6d072cb3f97a4441afd.png

Finally, the values of c9ed3f971ca58bcba4151efabe2740a17061ff66.png are:

acc451da60f97f7bc4c26c0a17cb35bc255f09e8.png

In the second sample, the values of 6f782226ddad4e081258745c5541a2391b7ac894.png are (5, 4, 2, 1, 1, 1). The distinct strings read in T2 are 00d4b70cbb220d41e61acd199e27795c30414ec0.png; note that 32f7c8b3d0c575014a6f6d1f48232767c84c6206.png can be read down to vertices 3 or 4.

提交

请先 登录

© 2025 FAQs Contact About