#P5353. 树上后缀排序
树上后缀排序
Problem Description
Given a tree rooted at with nodes, it is guaranteed that for every node from to , the index of its parent is smaller than its own index.
Each node has a character. The string represented by a node is defined as the string formed by concatenating all characters on the simple path from the current node up to the root.
Please sort these strings in lexicographical order.
In particular, if the strings represented by two nodes are exactly the same, their order is determined by the order of their parents: the one whose parent has a larger rank is considered larger. If they are still the same, then their order is determined by their node indices: the one with the larger index is considered larger.
Input Format
The first line contains a positive integer .
The second line contains integers , where denotes the parent of node .
The third line contains a string of length consisting of lowercase letters, where is the character on node .
Output Format
Output one line with positive integers. The -th integer denotes the node index that represents the string ranked -th.
5
1 1 3 2
abbaa
1 5 4 2 3
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5