CF501B.Misha and Changing Handles
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
米沙黑了 Codeforces 网站。随后,他决定允许所有用户更改自己的用户名(handle)。现在,一名用户可以任意多次更改其用户名,但每次设定的新用户名都不得与任何当前已被使用的用户名、或历史上曾被使用过的用户名相同。
米沙手头有一份用户名变更请求列表。在执行完所有请求后,他希望了解用户原始用户名与最终新用户名之间的对应关系。请帮助他完成这一任务。
输入格式
The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.
Next q lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.
第一行包含一个整数 q(1≤q≤1000),表示用户名变更请求的数量。
接下来的 q 行每行描述一个请求。
每个查询包含两个非空字符串 old 和 new,以空格分隔。字符串由小写和大写拉丁字母以及数字组成。字符串 old 和 new 互不相同。每个字符串的长度不超过 20。
请求按时间顺序给出。换言之,在执行某个查询时,恰好有一个人使用用户名 old,且用户名 new 当前未被任何人使用,也从未被任何人使用过。
输出格式
In the first line output the integer n — the number of users that changed their handles at least once.
In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
第一行输出整数 n —— 至少更改过一次昵称的用户数量。
接下来的 n 行中,输出用户旧昵称与新昵称之间的映射关系。每行必须包含两个字符串 old 和 new,以空格分隔,表示该用户在所有请求执行前的昵称为 old,所有请求执行完毕后的昵称为 new。各行的输出顺序可以任意。
每个更改过昵称的用户在此描述中必须恰好出现一次。
输入输出样例
输入#1
5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov
输出#1
3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123
输入解题思路,AI测评打分。不知道怎么写?