CF601D.Acyclic Organic Compounds

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree TT with nn vertices (numbered 11 through nn ) and a letter in each vertex. The tree is rooted at vertex 11 .

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

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

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

输入格式

The first line of the input contains one integer nn ( 1<=n<=3000001<=n<=300000 ) — the number of vertices of the tree.

The second line contains nn space-separated integers cic_{i} ( 0<=ci<=1090<=c_{i}<=10^{9} ).

The third line contains a string ss consisting of nn lowercase English letters — the ii -th character of this string is the letter in vertex ii .

The following n1n-1 lines describe the tree TT . Each of them contains two space-separated integers uu and vv ( 1<=u,v<=n1<=u,v<=n ) indicating an edge between vertices uu and vv .

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

输出格式

Print two lines.

On the first line, print over all 1<=i<=n1<=i<=n .

On the second line, print the number of vertices vv for which .

输入输出样例

  • 输入#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:

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

Finally, the values of are:

In the second sample, the values of are (5,4,2,1,1,1)(5,4,2,1,1,1) . The distinct strings read in T2T_{2} are ; note that can be read down to vertices 33 or 44 .

首页