[USACO 2010 Jan B]Word Morph
题号:NC24712
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Farmer John is playing a word game against his cows. It starts like this:
* Farmer John chooses a word, such as 'cat'
* The cows then choose their own word, perhaps 'dog'
Farmer John then must morph his word to the cows' word by performing a number of steps, each one of which changes one single letter at a time to make a new, valid word.
Your program should read a dictionary of valid words from file dict.txt. The file has no more than 25,000 words, each with length in the range 1..20. These 'words' contain only letters in the range 'a'..'z'. The same dictionary is used for all tests.
For this example, Farmer John could make the following sequence of four words:
      'cat' -> 'cot' -> 'cog' -> 'dog'
to morph words from the first word 'cat' to the final word 'dog' in just three moves. The cows will never give Farmer John an impossible task. Farmer John must get from his word to the cows' word in as few moves as possible.
You will be given a starting word and an ending word.  Determine and output a number which is the least number of legal letter changes required to morph the starting word to the ending word.

输入描述:

* Line 1: A single string that is the starting word
* Line 2: A single string that is the end word

输出描述:

* Line 1: A single integer that is the number of times a letter must be changed to transform the starting word into the ending word.
示例1

输入

复制
cat
dog

输出

复制
3