CF522A.Reposts

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.

These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.

Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.

有一天,Polycarp 在社交网络上发布了一张有趣的图片,并就自己用户名的颜色发起了一项投票。他的许多朋友开始将 Polycarp 的这个玩笑转发到自己的动态消息中。其中一些人又转发了这些转发,如此继续下去。

这些事件以一系列形如 "name1 reposted name2" 的字符串给出,其中 name1 是转发该玩笑的人的名字,name2 是 name1 从其动态消息中获取该玩笑的人的名字。保证对于每个字符串 "name1 reposted name2",用户 name1 在转发前尚未在其动态消息中拥有该玩笑,而 name2 在转发发生时已经拥有了该玩笑。Polycarp 的注册名为 "Polycarp",且最初该玩笑仅存在于他的动态消息中。

Polycarp 将该玩笑的流行度定义为最长转发链的长度。请输出 Polycarp 的玩笑的流行度。

输入格式

The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.

We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.

输入的第一行包含一个整数 nn(1≤n≤2001 \leq n \leq 200)——表示转发次数。接下来按转发发生的顺序给出 nn 条转发记录,每条记录独占一行,格式为“name1 reposted name2”。输入中的所有用户名均由小写或大写英文字母和/或数字组成,长度均为 22 至 2424 个字符(含端点)。

我们已知用户名不区分大小写,即仅在字母大小写上存在差异的两个用户名对应于同一社交网络用户。

输出格式

Print a single integer — the maximum length of a repost chain.

输出一个整数——转发链的最大长度。

输入输出样例

  • 输入#1

    5
    tourist reposted Polycarp
    Petr reposted Tourist
    WJMZBMR reposted Petr
    sdya reposted wjmzbmr
    vepifanov reposted sdya

    输出#1

    6
  • 输入#2

    6
    Mike reposted Polycarp
    Max reposted Polycarp
    EveryOne reposted Polycarp
    111 reposted Polycarp
    VkCup reposted Polycarp
    Codeforces reposted Polycarp

    输出#2

    2
  • 输入#3

    1
    SoMeStRaNgEgUe reposted PoLyCaRp

    输出#3

    2

输入解题思路,AI测评打分。不知道怎么写?

首页