Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2884.   C-N-Hawk's Dangerous Mission
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 541   Accepted Runs: 175



The famous spy, Cute Noodle Hawk(C-N-Hawk), is facing a dangerous mission. C-N-Hawk steals significant intelligence from the enemy. While leaving the dangerous area, he find problems. The area to the south of Hawk is dangerous, which is full of mines.

Input

Hawk will tell you the size of the dangerous area with two integers M and N (1 ≤ M, N ≤ 50). Then he will draw a map of M * N blocks with '.' or '@'. A block with '.' means it is safe and '@' means there is a mine in it. The dangerous area contains at least one mine. There are several test cases in the input, and the input will end with M = N = 0.

Output

C-N-Hawk can enter the dangerous area by moving to any block on the north edge and leave it by exiting from any block on the south edge. In the area, C-N-Hawk can move from the current block to an adjacent block. That means he can move in one of the four directions: north, east, south or west. Moving in diagonal is impossible.

C-N-Hawk should keep himself from the mines as far as possible. Please find a path to help him to arrive the south and make the path from the mines farthest.

The B-distance of a block is defined as the distance between the block and the nearest mine. It is calculate as Euclid Distance. For example, if the block (x1, y1) has the nearest mine in block (x2, y2), the distance is sqrt((x1-x2)2 + (y1-y2)2). The P-distance of a path is defined as the smallest B-distance on the path.

Please output the maximum P-distance for each cases, rounded to four decimal places. If C-N-Hawk can not arrive the south, the P-distance is consider as zero (0.0000).

Sample Input

4 5
@...@
@....
@@...
.....
0 0

Sample Output

1.4142
Hint:
The best path for the case is: (1,3)→(2,3)→(2,4)→(3,4)→(4,4).
Both the blocks (2,3) and (2,4) have the smallest B-distance 1.4142, so the P-distance is 1.4142.


Source: TJU Team Selection Contest 2007 (5)
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:Fxz. Developer: SuperHacker, G.D.Retop, Fxz