D. Tanya and Password
time limit per test
memory limit per test
input
output
n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password out. Each three-letter substring was written the number of times it occurred in the password. Thus, Tanya ended up with n
Then Tanya realized that dad will be upset to learn about her game and decided to restore the password or at least any string corresponding to the final set of three-letter strings. You have to help her in this difficult task. We know that dad's password consisted of lowercase and uppercase letters of the Latin alphabet and digits. Uppercase and lowercase letters of the Latin alphabet are considered distinct.
Input
n (1 ≤ n ≤ 2·105), the number of three-letter substrings Tanya got.
n
Output
NO".
YES", and then print any suitable password option.
Sample test(s)
input
5 aca aba aba cab bac
output
YES abacaba
input
4 abc bCb cb1 b13
output
NO
input
7 aaa aaa aaa aaa aaa aaa aaa
output
YES aaaaaaaaa
欧拉路径,弗罗莱算法 主要参见下面的资料:
本题给出一个字符串所有的连续3位的字符串,要求找出一个满足条件的原字符串。
把2个字符(如‘aa')为点,
每个3字符串,前2字符向后两字符连边(如'abc':'ab'--->‘bc')
原题转为求新图上的欧拉路径。
PS:注意特判图不连通的情况,注意删边。