QOJ.ac

QOJ

時間限制: 8 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#14237. 村民交易

统计

Steve 正在规划他的退休生活。他决定在一个住满村民的美丽小镇定居。当然,他不想在退休后还要离开村庄去挖矿,所以他计划现在就收集好未来需要的所有资源。

不幸的是,他不知道自己未来会需要什么材料。然而,小镇上到处都是愿意为了绿宝石做任何事的村民,包括收集他未来可能需要的任何资源。因此,Steve 想要创造一个稳定的绿宝石来源,供他余生使用。

事实证明,所有的村民都喜欢进行交易。具体来说,每个村民都会提供一定数量的交易,Steve 可以用某种物品交换另一种物品。Steve 想知道,假设他可以在退休前有策略地收集有限数量的任何资源,是否可能通过重复交易来创造无限的绿宝石来源。写一个程序来帮助他判断这是否可行。

输入格式

输入的第一行包含一个整数 $1 \le N \le 1\,000$,表示村民的数量。

接下来的行描述了这 $N$ 个村民中每一个的交易。每个村民的输入以一行开始,该行包含一个整数 $1 \le t \le 10$,表示该村民提供的交易数量。接下来是 $t$ 行,每行包含整数 $1 \le a_1 \le 64$、字符串 $s_1$、整数 $1 \le a_2 \le 64$ 和字符串 $s_2$,用空格隔开,表示 Steve 可以将 $a_1$ 个名为 $s_1$ 的物品给该村民,以换取 $a_2$ 个名为 $s_2$ 的物品。

假设最多有 $5\,000$ 种可交易的物品,每种物品都有一个唯一的单单词名称,由 1-16 个英文大写或小写字母组成。绿宝石使用的名称是 "Emerald"(区分大小写),尽管并非所有村民都交易绿宝石,因此输入中可能不包含绿宝石交易。

输出格式

如果 Steve 有可能交易得到无限的绿宝石,输出 "yes"。否则,输出 "no"。

样例

输入样例 1

2
3
6 Paper 3 Book
6 Book 2 Bookshelf
1 Bookshelf 8 Paper
1
32 Paper 1 Emerald

输出样例 1

yes

输入样例 2

1
2
32 Stick 1 Emerald
3 Emerald 64 Stick

输出样例 2

no

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.