测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A10119. Acyclic Organic Compounds

编程题 普及/提高-

题目描述

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 ![](/uploads/acgo/image/b514613742ea7aa1_6ffe21f4c16b.jpeg).

Also, there's a number $c_{v}$ assigned to each vertex $v$ . We are interested in vertices with the maximum value of ![](/uploads/acgo/image/a2aa7c2d151a0aad_ddd4b0aef95e.jpeg).

You should compute two statistics: the maximum value of ![](/uploads/acgo/image/a2aa7c2d151a0aad_ddd4b0aef95e.jpeg) and the number of vertices $v$ with the maximum ![](/uploads/acgo/image/a2aa7c2d151a0aad_ddd4b0aef95e.jpeg).

输入格式

The first line of the input contains one integer $n$ ( $1<=n<=300000$ ) — 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.

输出格式

Print two lines.

On the first line, print ![](/uploads/acgo/image/c6fbfdc44dfa0af2_3c580899fbf4.jpeg) over all $1<=i<=n$ .

On the second line, print the number of vertices $v$ for which ![](/uploads/acgo/image/59314b87e359ec40_a0a4c548e046.jpeg).

输入输出样例

输入 #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
输出 #1
51
3
输入 #2
6
0 2 4 1 1 1
raaaba
1 2
2 3
2 4
2 5
3 6
输出 #2
6
2

说明/提示

In the first sample, the tree looks like this:

![](/uploads/acgo/image/80fa8448e334b999_cf888875b75e.jpeg)The sets of strings that can be read from individual vertices are:

![](/uploads/luogu/CF601D/b0a25806e20ff995abfb34a167834abd113ae6f1_8fe494da0cdd.png)Finally, the values of ![](/uploads/acgo/image/e1e818a286129403_6b20a6dc251e.jpeg) are:

![](/uploads/luogu/CF601D/6c3fc4aa4c72ec4c2646ac39d7110bd6544e120f_53c275d57223.png)In the second sample, the values of ![](/uploads/luogu/CF601D/4c35255ca2e85f9a2c304b6b5d98f8aa96f62b0c_c7f29d2238dc.png) are $(5,4,2,1,1,1)$ . The distinct strings read in $T_{2}$ are ![](/uploads/luogu/CF601D/6427dc79a89c97e7e81a3e52fb54938acda3e0b8_e01f4d8de624.png); note that ![](/uploads/acgo/image/811ad8843afe44cf_d5bf34a88839.jpeg) can be read down to vertices $3$ or $4$ .
上一题 去做题 下一题