A10119 | Acyclic Organic Compounds
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 .
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 .
输入格式
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.
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  over all $1<=i<=n$ .
On the second line, print the number of vertices $v$ for which .
On the first line, print  over all $1<=i<=n$ .
On the second line, print the number of vertices $v$ 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)$ . The distinct strings read in $T_{2}$ are ; note that  can be read down to vertices $3$ or $4$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted