#P10006. [集训队互测 2023] 超现实树
[集训队互测 2023] 超现实树
Background
Alek likes competitive programming, and especially likes surreal trees. A surreal tree, as the name suggests, is a tree with surreal numbers on it.
Problem Description
Alek thinks that, for a constant , a string is called a “-surreal number string” if it contains only the characters , and:
- The empty string is a -surreal number string.
- If are -surreal number strings, then is a -surreal number string.
- If strings are all -surreal number strings, then $\texttt{\{} + s_1 + \texttt{|} + s_2 + \texttt{|} + \cdots + \texttt{|} + s_{k + 1} + \texttt{\}}$ is a -surreal number string.
- -surreal number strings are only those described above.
You are given an unrooted tree with nodes, numbered . Each node has a character .
Given an integer , for each , Alek wants you to compute: how many ordered pairs with are such that the string obtained by concatenating, in order, the characters along the unique simple path from node to node is a -surreal number string.
Input Format
The first line contains two integers , representing the number of nodes in the tree, and the upper limit of for which you need to compute answers.
The second line contains a string , where the -th character of is the character on node .
The next lines each contain two integers , indicating that there is an edge connecting node and node .
Output Format
Output one line with integers, representing the answers for , respectively.
5 3
|{}}}
2 1
3 2
4 1
5 1
1 2 0 0
10 8
|}||}{|{{{
2 1
3 1
4 3
5 2
6 5
7 5
8 4
9 2
10 3
2 0 1 1 0 0 0 0 0
见附加文件 ex_surreal3.in。
见附加文件 ex_surreal3.ans。
Hint
For all testdata, , , .
- Subtask 1 (5 points): .
- Subtask 2 (20 points): For every edge , .
- Subtask 3 (5 points): , .
- Subtask 4 (15 points, depends on Subtask 3): .
- Subtask 5 (25 points, depends on Subtask 1): .
- Subtask 6 (30 points, depends on Subtask 1, 2, 3, 4, 5): No special constraints.
Translated by ChatGPT 5