#P16959. [SCCPC 2026] 精灵对战
[SCCPC 2026] 精灵对战
Problem Description
Little loves playing Roco Kingdom, and especially likes having spirit battles with other players.
There are now types of spirits, numbered from to . There are counter relationships between spirits. For each type of spirit, it is countered by at most types of spirits.
When Little 's spirit fights the opponent's spirit , the result is as follows:
- If counters and does not counter , then is knocked down, and continues fighting.
- If counters and does not counter , then is knocked down, and continues fighting.
- If there is no counter relationship between and , then they knock each other out.
- If and counter each other, then Little can defeat the opponent's spirit with excellent game skills, that is, is knocked down, and continues fighting.
Little already knows the opponent's spirit deployment order in advance. It is a sequence of length , and repeated spirits may appear in the sequence.
Little needs to arrange his own spirit deployment order properly to defeat all of the opponent's spirits. During the battle, if the current spirit is not knocked down, it cannot be switched out. Only after the current spirit is knocked down or both sides knock each other out can Little send out a new spirit. Little may send out the same type of spirit multiple times.
Sending out one spirit costs . Please find the minimum total cost required for Little to defeat all of the opponent's spirits.
Input Format
The first line contains three integers (), representing the number of spirit types, the length of the opponent's deployment sequence, and the maximum number of spirit types that can counter each spirit type.
In the next lines, for the -th line, it first contains an integer (), representing the number of spirit types that counter the -th type of spirit; then it contains integers (), representing the spirit IDs that counter the -th type of spirit.
The last line contains integers (), representing the opponent's spirit deployment sequence.
The input guarantees that within each line of counter relationships, all spirit IDs are distinct, and there is no self-counter relationship.
Output Format
Output one line with one integer, representing the minimum total cost required for Little to defeat all of the opponent's spirits.
3 4 2
1 2
2 3 1
1 1
2 2 2 1
1
Hint
Translated by ChatGPT 5