QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100

#13975. 必胜

통계

Curtis 的蓝图

Curtis 再次向红猪(Porco Rosso)发起决斗。Curtis 有了一个新计划:这一次,他要制造一架完美的飞机。他设计了一份包含 $R$ 张蓝图的清单。每张蓝图都指明了制作一个独特的飞机零部件所需的原料。这些飞机零部件也可以作为其他蓝图的原料。在击败红猪的计划中,Curtis 可以无限量地使用 $N$ 种基础原料。

使用原始蓝图,Curtis 可以制作出这些蓝图所描述的任何飞机零部件;然而,现在出现了一个问题。菲奥(Fio)在 Curtis 的蓝图里动了手脚,她在其中一张蓝图中多写了一种原料。Curtis 一直在原地打转,试图找出是哪张蓝图受到了这个额外原料的影响。不过,他意识到自己可能仍然能够制作出所有的飞机零部件。

作为 Curtis 的机械师,你的任务是找出菲奥破坏了什么。你已经确定菲奥在恰好一张蓝图中恰好添加了一种原料。因为菲奥很狡猾,她选择了一种已有的原料进行添加。如果 Curtis 仍然能够制作出他的飞机(即名为 airplane 的零部件),请告诉 Curtis 他已经准备好击败红猪了。否则,告诉 Curtis 有多少个零部件他无法再制作。

输入格式

第一行输入包含两个空格分隔的整数 $N$ 和 $R$($1 \le N, R \le 500$),分别代表基础原料的数量和蓝图的数量。

接下来的 $N$ 行是基础原料。这些行中的每一行都包含一个字符串,代表一种原料。每个字符串仅包含小写字母、数字和连字符。原料是唯一的。

接下来的 $R$ 对行是蓝图。每对行的第一行包含一个整数 $R_i$,表示第二行中空格分隔的字符串数量。 每对行的第二行包含 $R_i$ 个空格分隔的字符串。该行的第一个字符串是该蓝图制作出的飞机零部件。其余的字符串包含建造该零部件所需的原料。所有蓝图都至少需要一种原料。

保证 $\sum R_i \le 500\,000$。保证输入中的所有字符串要么是基础原料,要么是某张蓝图的产物。输入中的任何字符串都仅由小写字母 a - z、数字 0 - 9 和连字符 - 组成。此外,每个字符串的长度不超过 36 个字符。

输出格式

如果 Curtis 仍然能够制作出他的飞机,输出一行,包含字符串 GUARANTEED VICTORY(不包含引号)。否则,输出一行,包含 Curtis 无法再制作的飞机零部件数量。

样例

输入样例 1

4 3
wrench
monkey
steel
engine
3
propeller steel monkey
3
monkeywrench monkey wrench
5
airplane propeller monkeywrench engine steel

输出样例 1

GUARANTEED VICTORY

输入样例 2

1 2
life
3
chicken life egg
3
egg chicken life

输出样例 2

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.