#P16959. [SCCPC 2026] 精灵对战

    ID: 19043 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP贪心四川2026省赛/邀请赛

[SCCPC 2026] 精灵对战

Problem Description

Little zz loves playing Roco Kingdom, and especially likes having spirit battles with other players.

There are now nn types of spirits, numbered from 11 to nn. There are counter relationships between spirits. For each type of spirit, it is countered by at most kk types of spirits.

When Little zz's spirit AA fights the opponent's spirit BB, the result is as follows:

  • If AA counters BB and BB does not counter AA, then BB is knocked down, and AA continues fighting.
  • If BB counters AA and AA does not counter BB, then AA is knocked down, and BB continues fighting.
  • If there is no counter relationship between AA and BB, then they knock each other out.
  • If AA and BB counter each other, then Little zz can defeat the opponent's spirit with excellent game skills, that is, BB is knocked down, and AA continues fighting.

Little zz already knows the opponent's spirit deployment order in advance. It is a sequence of length mm, and repeated spirits may appear in the sequence.

Little zz 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 zz send out a new spirit. Little zz may send out the same type of spirit multiple times.

Sending out one spirit costs 11. Please find the minimum total cost required for Little zz to defeat all of the opponent's spirits.

Input Format

The first line contains three integers n,m,kn,m,k (1n,m105,1k301 \le n,m \le 10^5, 1 \le k \le 30), 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 nn lines, for the ii-th line, it first contains an integer sis_i (0sik0 \le s_i \le k), representing the number of spirit types that counter the ii-th type of spirit; then it contains sis_i integers xi,1,xi,2,,xi,six_{i,1},x_{i,2},\ldots,x_{i,s_i} (1xi,jn,xi,ji1 \le x_{i,j} \le n,x_{i,j} \neq i), representing the spirit IDs that counter the ii-th type of spirit.

The last line contains mm integers a1,a2,,ama_1,a_2,\ldots,a_m (1ain1 \le a_i \le n), 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 zz 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