Logo
(追記) (追記ここまで)

9123번 - Word Ladder 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB92121222.642%

문제

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:

  • A line with two space-separated integers n (2 ≤ n ≤ 100) and l (1 ≤ l ≤ 20): the number of words and their length.
  • n lines with a word, each consisting of l lowercase letters (a - z).

출력

For each testcase:

  • a single line with the words in a ladder of minimal length, separated by a single space.

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

1
9 3
alt
spy
sea
opt
pea
ape
spa
apt
ale

예제 출력 1

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.

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2007 Preliminaries A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /