#P1341. 无序字母对

    ID: 338 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论福建省历届夏令营深度优先搜索,DFS欧拉回路

无序字母对

Description

Given nn distinct unordered letter pairs (case-sensitive; unordered means the two letters in a pair can appear in either order), construct a string with (n+1)(n+1) letters such that each letter pair appears in this string.

Input Format

The first line contains a positive integer nn.

Each of the next nn lines contains two letters, indicating that these two letters must be adjacent.

Output Format

Output a string that satisfies the requirement.

If no such string exists, output No Solution.

If multiple solutions exist, output the lexicographically smallest one (i.e., the earlier letters should have smaller ASCII codes).

4
aZ
tZ
Xt
aX
XaZtX

Hint

The number of different unordered letter pairs is finite, and the scale of nn can be calculated.

Translated by ChatGPT 5