QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 256 MB مجموع النقاط: 100

#15759. VAN DINSKY

الإحصائيات

你需要帮助未来的画家 Vincent van Dinsky 为他的画作调制颜色。他的导师给了他一本调色规则书和一个调色盘,并让他通过实验调制出画作所需的颜色,直到他找到调制出画作中每种颜色所需的最少调色次数。

注意事项:

  • 所有颜色的名称仅包含字符 a-z0-9(小写字母和数字)。
  • 一条调色规则由写在同一行上的三种颜色组成,表示“第一种颜色与第二种颜色混合得到第三种颜色”——例如 yellow cyan green(黄色和青色混合得到绿色)。
  • Van Dinsky 先生不愿意进行随机的调色实验——如果他在书中找不到混合黄色和绿色的结果,他就绝不会尝试进行这个操作。他的逻辑推理能力也很差——例如,如果书中写着 yellow+cyan=greenyellow+magenta=redred+cyan=black,他不会假定 green+magenta=black(除非书中明确说明了混合绿色和洋红色的结果)。另一方面,他完全清楚混合的顺序无关紧要——混合黄色和绿色与混合绿色和黄色是相同的。

输入格式

输入按顺序包含:

  • 书中所有的调色规则
  • 一个空行(在样例中为 <done/>
  • 一个或多个数据集(绘画任务),每个数据集由两行组成:
    • 初始调色盘上可用的所有颜色
    • 绘画所需的所有颜色

输出格式

对于每个绘画任务(即每个数据集),输出一行。在该行中,对于绘画所需的每种颜色,输出产生该目标颜色所需的最少调色次数(从初始调色盘上可用的颜色开始;如果无法获得目标颜色,则输出 -1)。

数据范围

你可以认为输入是正确的,规则书中的调色规则少于 $50000$ 条,颜色总数少于 $1000$ 种。

样例

输入样例 1

cyan yellow green
cyan magenta blue
yellow magenta red
red green black
<done/>
cyan yellow magenta pink
cyan black pink red brown
cyan yellow red
blue black

输出样例 1

0 3 0 1 -1
-1 2

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.