#C4361. Word Transformation Challenge

    ID: 47891 Type: Default 1000ms 256MiB

Word Transformation Challenge

Word Transformation Challenge

You are given a starting word, a target word, and a dictionary of valid words. Your task is to determine the shortest transformation sequence from the starting word to the target word. In each step, you may change exactly one letter, and each intermediate word must exist in the given dictionary.

If the transformation sequence exists, output YES on the first line and then the sequence of words (separated by a space) on the next line. If there is no valid transformation, output NO.

Note: The transformation must change exactly one letter at a time, and the length of all words involved is the same.

For example: converting "hit" to "cog" given the dictionary ["hot", "dot", "dog", "lot", "log", "cog"] results in:

YES
hit hot dot dog cog

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains the start word.
  2. The second line contains the target word.
  3. The third line contains an integer n, the number of words in the dictionary.
  4. The next n lines each contain a word from the dictionary.

All words will have the same length.

outputFormat

The output is printed to standard output (stdout). If a valid transformation exists, print YES on the first line and on the second line print the transformation sequence (words separated by a single space). If no valid transformation exists, print NO.

## sample
hit
cog
6
hot
dot
dog
lot
log
cog
YES

hit hot dot dog cog

</p>