CF601D.Acyclic Organic Compounds
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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
.
Also, there's a number c__v 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
.
给你一棵有 n 个顶点(编号为 1 到 n)的树 T,每个顶点上标有一个字母。该树以顶点 1 为根。
考虑某个顶点 v 的子树 Tv。我们可以沿着每一条从 v 出发、终点为 Tv 中某个顶点(可以是 v 自身)的简单路径读出一个字符串。记这样能读出的不同字符串的个数为
。
此外,每个顶点 v 还被赋予一个数值 cv。我们关注使得
取得最大值的那些顶点。
你需要计算两个统计量:
的最大值,以及使得
取得该最大值的顶点 v 的个数。
输入格式
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 ≤ 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.
输入的第一行包含一个整数 n(1≤n≤300000)—— 树的顶点数。
第二行包含 n 个用空格分隔的整数 ci(0≤ci≤109)。
第三行包含一个由 n 个小写英文字母组成的字符串 s —— 该字符串的第 i 个字符表示顶点 i 上的字母。
接下来的 n−1 行描述树 T。每行包含两个用空格分隔的整数 u 和 v(1≤u,v≤n),表示顶点 u 与顶点 v 之间存在一条边。
保证输入描述的是一棵树。
输出格式
Print two lines.
On the first line, print
over all 1 ≤ i ≤ n.
On the second line, print the number of vertices v for which
.
输出两行。
第一行,输出对所有 1 ≤ i ≤ n 的
。
第二行,输出满足
的顶点 v 的个数。
输入输出样例
输入#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). The distinct strings read in _T_2 are
; note that
can be read down to vertices 3 or 4.
在第一个样例中,树的结构如下所示:

从各个顶点出发可读出的字符串集合为:

最终,
的值为:

在第二个样例中,
的值为 (5, 4, 2, 1, 1, 1)。在 _T_₂ 中可读出的不同字符串为
;注意,
可沿路径向下读至顶点 3 或顶点 4。
输入解题思路,AI测评打分。不知道怎么写?