#P7206. [COCI 2019/2020 #3] Lampice
[COCI 2019/2020 #3] Lampice
Description
Mirko decorates a Christmas tree with LED lights. Their colors are known, and they are connected by wires.
After finishing, Mirko carefully admires his work. He is attracted by a special pattern called a "palindrome segment". A "palindrome segment" is a path from to such that the sequence of light colors along the path from to is the same as the sequence of light colors along the path from to .
Find the longest "palindrome segment" in the Christmas tree.
Input Format
The first line contains an integer , the number of LED lights.
The second line contains a string of lowercase English letters, where the -th letter represents the color of the -th light.
The next lines each contain two integers , indicating that and are connected by a wire.
Output Format
Output the longest "palindrome segment" in the Christmas tree.
7
imanade
1 2
2 3
3 4
4 5
5 6
6 7
3
4
aabb
1 2
1 3
3 4
2
8
acdbabcd
1 6
6 7
6 3
3 4
4 5
5 2
8 5
5
Hint
Constraints
| Subtask | Score | Constraints |
|---|---|---|
| The -th light is directly connected to the -th light () | ||
| At most lights are directly connected to another light | ||
| None |
For of the testdata, $1 \le N \le 5 \times 10^4, 1 \le A, B \le N, A \neq B$.
Notes
The score of this problem is set according to the original COCI problem, with a full score of .
Translated from COCI2019-2020 CONTEST #3 T4 Drvca.
Translated by ChatGPT 5
京公网安备 11011102002149号