#P10536. [Opoi 2024] 二十六点
[Opoi 2024] 二十六点
Background
Twenty-six points:
。 。 。 。 。 。 。 。 。 。 。 。 。
。 。 。 。 。 。 。 。 。 。 。 。 。
Making twenty-six points is really fun, and in order to make up four problems, this number-composition problem with only kinds of weights was created.
Problem Description
You are given a rooted tree with nodes, rooted at . The -th node has a color , where , and a value .
For each node , there is a path from it to every node in its subtree (note that the order is from itself to a node in its subtree), for a total of paths.
Now, ignore the -nd to the -th nodes on each of these paths. In particular, if , then no nodes are ignored. Treat the path after ignoring as a sequence, where the weight of each node in the sequence is the of the node on the path. For each node, find the maximum, over all its sequences, of the length of the longest non-decreasing subsequence.
Note: If a path has nodes, this is equivalent to ignoring all nodes on this path except the first node.
Input Format
The first line contains an integer .
The second line contains integers .
The third line contains lowercase letters , with no spaces between characters.
Next lines describe the tree . Each line contains two integers , meaning there is an edge between and .
There may be extra spaces at the end of lines (use getchar() with caution).
Output Format
Output lines, the answer for each node, in order of increasing index.
7
2 1 1 9 8 5 1
zzabcad
1 2
2 3
3 4
3 5
5 6
5 7
3
3
3
1
1
1
1
12
1 2 2 4 1 3 4 3 1 4 3 1
baabbbbbbbaa
4 6
5 7
1 2
12 10
8 2
10 11
5 9
10 3
2 3
4 3
4 5
5
4
3
1
2
1
1
1
1
1
1
1
Hint
Explanation of Sample 1:
The shape of the tree in the sample:

For node : .
| Sequence | Weights | Length of LNDS | LNDS |
|---|---|---|---|
| 1 | z | 1 | z |
| 1 3 | za | ||
| 1 3 4 | zab | 2 | ab |
| 1 3 5 | zac | ac | |
| 1 3 5 6 | zaca | ||
| 1 3 5 7 | zacd | 3 | acd |
The LNDS with the maximum length: acd.
Node is the same as node .
For node : .
| Sequence | Weights | Length of LNDS | LNDS |
|---|---|---|---|
| 3 | a | 1 | a |
| 3 4 | ab | ab | |
| 3 5 | ac | 2 | ac |
| 3 5 6 | aca | ||
| 3 5 7 | acd | 3 | acd |
The LNDS with the maximum length: acd.
For , each of their sequences contains only the node itself, so output .
Constraints
This problem uses Subtask scoring.
| Subtask | Limit | Pts |
|---|---|---|
| 0 | 5 | |
| 1 | 15 | |
| 2 | 30 | |
| 3 | Empty | 50 |
For of the testdata:
.
, is a lowercase letter, and .
The given tree is connected and valid.
Translated by ChatGPT 5