- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
The Barareh village is on fire due to the attack of the virtual enemy. Several places are already on fire and the fire is spreading fast to other places. Khorzookhan who is the only person remaining alive in the war with the virtual enemy, tries to rescue himself by reaching to the only helicopter in the Barareh villiage.
Suppose the Barareh village is represented by an grid. At the initial time, some grid cells are on fire. If a cell catches fire at time , all its 8 vertex-neighboring cells will catch fire at time . If a cell catches fire, it will be on fire forever. At the initial time, Khorzookhan stands at cell and the helicopter is located at cell . At any time , Khorzookhan can move from its current cell to one of four edge-neighboring cells, located at the left, right, top, or bottom of its current cell if that cell is not on fire at time . Note that each move takes one second.
Your task is to write a program to find the shortest path from to avoiding fire.
ورودی
There are multiple test cases in the input. The first line of each test case contains three positive integers and (), where and indicate the size of the test case grid , and denotes the growth rate of fire. The next lines, each contains a string of length , where the th character of the th line represents the cell of the grid. Cells which are on fire at time , are presented by character f
. There may exist no f
in the test case. The helicopter and Khorzookhan are located at cells presented by t
and s
, respectively. Other cells are filled by -
characters. The input terminates with a line containing 0 0 0
which should not be processed.
خروجی
For each test case, output a line containing the shortest time to reach t
from s
avoiding fire. If it is impossible to reach t
from s
, write Impossible
in the output.
مثال
ورودی نمونه ۱
خروجی نمونه ۱
ارسال پاسخ برای این سؤال