QOJ.ac

QOJ

実行時間制限: 8 s メモリ制限: 2048 MB 満点: 100

#7668. 游戏策略

統計

Alice 和 Bob 正在玩一个棋盘游戏。棋盘被划分为标记为 $a, b, c, d, \dots$ 的位置,玩家使用一枚棋子来标记当前位置。游戏的每一轮包含两个步骤:

  1. Alice 做出选择。根据当前位置,她有不同的选项,每个选项都是一组位置。Alice 从可用的位置集合中选择一个集合 $S$。
  2. Bob 做出选择。他的选择是 Alice 在第 1 步中选择的集合 $S$ 中的一个位置 $p$。Bob 将棋子移动到位置 $p$,该位置即为下一轮开始时的位置。

在第一轮开始之前,每位玩家独立选择一个位置并在游戏开始时揭晓。Bob 的位置即为游戏开始的位置。如果 Alice 能强迫 Bob 将棋子移动到她所选择的位置,Alice 就赢得了游戏。为了增加趣味性,他们决定如果 Bob 输了,他将支付给 Alice 一定金额,但 Alice 在每一轮结束后必须支付给 Bob 一定金额。如果到达了 Alice 的目标位置,或者 Alice 的现金用尽,游戏结束。

Alice 和 Bob 都采取最优策略:如果可能,Alice 总是会选择一个能导致她赢得游戏的选项,而 Bob 总是会试图阻止 Alice 获胜。

对于所有可能的起始位置和目标位置,Alice 希望你确定她是否能赢得游戏,如果能,需要多少轮。

输入格式

输入包含一组测试用例。第一行包含位置的数量 $n$ ($1 \le n \le 25$)。这 $n$ 个位置使用前 $n$ 个小写英文字母标记。测试用例的其余部分包含 $n$ 行,每行对应一个位置 $p$,按字母顺序排列。位置 $p$ 的行包含 Alice 在该位置可用的选项。它以选项数量 $m$ ($1 \le m < 2^n$) 开头,随后是 $m$ 个不同的字符串,每个字符串对应一个选项。每个字符串包含 Bob 在 Alice 选择该选项时可用的位置。字符串至少包含 1 个字符,字符(对应于有效的棋盘位置)按字母顺序排列,且没有重复字符。测试用例的选项总数最多为 $10^6$。

输出格式

对于每个位置 $p$(按字母顺序),显示一行。在该行中,对于每个位置 $q$(按字母顺序),显示 Alice 在起始位置为 $p$ 时,保证到达位置 $q$ 所需的最小轮数,如果 Alice 不能保证从 $p$ 到达 $q$,则输出 $-1$。

样例

样例输入 1

2
2 ab b
1 b

样例输出 1

0 1
-1 0

样例输入 2

3
1 b
2 b a
2 ab ac

样例输出 2

0 1 -1
1 0 -1
2 2 0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.