luogu#P7005. [NEERC2013] Join the Conversation

[NEERC2013] Join the Conversation

题目描述

Abstract Communication Mastership (ACM) is a software company that develops a unique social network called tWinter.

Each tWinter user has a handle that starts with a commercial at (@)(‘@') character. Users of tWinter social network publish short messages to the network.

If a user's message contains another user's handle (preceded by a space or at the beginning of the message, and followed by a space or at the end of the message) then it is called a mention.

A sequence of messages is called a conversation if each message in the sequence (except the first one) contains a mention of the author of the previous message in the sequence.

You are hired to find the longest conversation in the given chronological log of messages.

输入格式

The first line of the input file contains an integer n(1n50000)n (1 \le n \le 50 000) -- the number of messages in the chronological log.

Each of the next nn lines contains a message preceded by its author's handle, a colon (:)(‘:') character, and a space.

Each message is at most 139139 characters long. Each handle is at most 2020 characters long and does not contain colons or spaces.

The input file contains only characters with ASCII codes between 3232 and 126126 , inclusive, and line breaks.

输出格式

On the first line of the output file write the length of the longest conversation in the given log. On the second line write 1based1-based indices of the messages in that conversation in ascending order.

If there are multiple longest conversations, write any one of them.

题目大意

Abstract Communication Mastership (ACM)是一家软件公司,开发一种名为tWinter“tWinter”的独特社交网络。

每个tWinter“tWinter”用户都有一个句柄,句柄由(‘(’‘‘’‘‘’@‘@’‘′’‘′’)‘)’开头。

每个tWinter“tWinter”社交网络的用户可以向网络发布短消息。

如果用户的消息包含另一个用户的句柄(句柄前面是空格或句柄是消息的开头并且后跟空格或消息末尾),则称为提及。

如果消息序列中的每条消息(第一条消息除外)都提及序列中前一条消息的作者,则该消息序列称为会话。

您需要在给定的消息时间顺序日志中查找最长的对话。

输入格式

输入文件共n+1n+1行;

第一行包含一个整数n(1n50000)n(1≤n≤50000)为消息日志中消息个数;

接下来nn行每行一条消息,前面是其作者的句柄,句柄后是一个冒号,冒号后为消息正文。

每条消息长度最多为139139个字符。每个手柄长度(不包含冒号或空格)最多为2020个字符。

输入文件仅包含 ASCII 代码介于32和126(含)之间和换行符。

输出格式

输出文件共22行;

第一行上,写入给定日志中最长对话的长度;

在第二行写该对话中消息基于1的索引,按升序排列。

说明/提示

时间限制:2S;

空间限制:128MB。

6
@Petr: Leaving for #NEERC tomorrow!
@Roman: This #NEERC is going to be awesome!
@Stone_in_forest: Nothing happened today.
@NEERCNews: @Petr Don't forget an umbrella :)
@Lydia: @NEERCNews cares about @Petr - so cute ^_^
@Lydia: @Lydia @NEERCNews @Petr it won't be raining though!

3
1 4 5

提示

Time limit: 2 s, Memory limit: 128 MB.