|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||0||0||0||0.000%|
A word ladder is a sequence of words, in which two consecutive words differ by exactly one letter. An example of such a ladder (usually arranged vertically, hence the “ladder”) would be: beer, brew, brow, word, down. Note that to get from one word to the next, the letters may be rearranged, and exactly one letter is changed.
For this problem, you will be given a dictionary of distinct words, all of the same length. Your task is to write a program that finds a word ladder of minimal length, such that the first and last word of the ladder have no letters in common.
On the first line an integer t (1 ≤ t ≤ 100): the number of test cases. Then for each test case:
For each testcase:
It is guaranteed that at least one such ladder can be constructed. If there is more than one, output the one that comes first lexicographically.
1 9 3 alt spy sea opt pea ape spa apt ale
ale alt apt opt
If s and t are strings of equal length and si denotes the ith character of s, then s precedes t lexicographically if for some i: si < ti and sj = tj for all j < i.