QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#16748. Genealogy

Statistiques

众所周知,历史文献和描述中的日期往往给得相当不准确。在对历史事件的描述中,最接近日期的表述常常是类似于“在亚伯拉罕之子以撒的时代”这样的话。

替代历史的爱好者莫芬科(Mofenko)教授想要确定,从给定的名单中,能够组成由父亲到儿子的最长人物链的长度。借助这些信息,他可以编造出许多文献无法反驳的、有趣的替代历史。

对于名单中的每个人,给出了他的姓氏、名字以及他父亲的名字。父亲和儿子的姓氏总是相同的。幸运的是,名单中所有人的名字都是互不相同的。

输入格式

输入的第一行包含一个整数 $N$:人物描述的数量($1 \le N \le 10^5$)。

接下来的 $N$ 行,每行包含一个人的描述,格式如下:姓氏、名字、单词 “son of” 以及他父亲的名字。

所有的名字和姓氏都以大写英文字母开头,除首字母外的所有字母均为小写英文字母。相邻的单词之间用单个空格分隔。每个名字和每个姓氏的长度不超过 10。

请注意,名单中的某些人的父亲可能不在名单中,但这个父亲不应该被包含在链中。保证名单中所有 $N$ 个人的名字两两不同;然而,这一限制可能不适用于名单之外的人的名字。

输出格式

输出一个整数:最长链中的人数。

样例

输入样例 1

7
Bible Isaak son of Abraham
Bible Jacob son of Isaak
Ivanov Ivan son of Petr
Ivanov Protopop son of Vasiliy
Ivanov Vasiliy son of Ivan
Ivanov Petr son of Vasiliy
Bible Judah son of Jacob

输出样例 1

4

输入样例 2

3
Ivanov Ivan son of Petr
Ivanov Petr son of Vasiliy
Petrov Vasiliy son of Ivan

输出样例 2

2

说明

  • 在第一个样例中,最长的链为:Ivanov PetrIvanov IvanIvanov VasiliyIvanov Protopop
  • 在第二个样例中,最长的链为:Ivanov PetrIvanov Ivan

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.