#P11088. [ROI 2021] 穿孔卡片 (Day 1)
[ROI 2021] 穿孔卡片 (Day 1)
Background
Translated from ROI 2021 D1T1.
Problem Description
A punched card is a strip consisting of small squares, where each square either contains a lowercase English letter or is a hole.
There are such punched cards. Given a string of length , arrange all punched cards in some order so that after stacking them from top to bottom, the result becomes . In other words, you need to determine the order of the punched cards. When they are stacked together, for every position , the -th character of the string must be the same as the character on the first punched card (from top to bottom) that has a letter at position .
If for some , there is no punched card that has a letter at this position, then it is impossible to obtain the target string .
Input Format
The first line contains two integers , representing the number of punched cards and the number of squares.
The second line contains a string of length , consisting of lowercase English letters.
In the next lines, each line describes one punched card.
First, an integer is given, meaning how many positions on this punched card contain letters. It is guaranteed that the sum of all does not exceed .
Then follows the description of the letters on this punched card: for each integer , there is an integer and a character (, is a lowercase English letter), meaning that the character at position is . All other positions are holes. It is guaranteed that the positions with letters on each punched card are in increasing order, i.e., .
Output Format
If there exists a correct way to arrange the punched cards, output integers , where is the index of the top card, is the index of the second card, and so on, and is the index of the bottom card.
If there are multiple possible answers, you may output any of them. If there is no correct arrangement, output -1.
1 1
a
1 1 a
1
3 4
glhf
3 1 r 3 h 4 i
3 1 r 2 l 3 o
2 1 g 4 f
3 1 2
2 2
aa
2 1 a 2 b
2 1 b 2 a
-1
Hint
Explanation for sample :

Constraints:
| Subtask | Score | ||
|---|---|---|---|
Translated by ChatGPT 5