码迷,mamicode.com
首页 > 其他好文 > 详细

ural 1145. Rope in the Labyrinth

时间:2015-12-26 11:41:56      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

1145. Rope in the Labyrinth

Time limit: 0.5 second
Memory limit: 64 MB
A labyrinth with rectangular form and size m × n is divided into square cells with sides‘ length 1 by lines that are parallel with the labyrinth‘s sides. Each cell of the grid is either occupied or free. It is possible to move from one free cell to another free cells that share a common side with the cell. One cannot move beyond the labyrinth‘s borders. The labyrinth is designed pretty specially: for any two cells there is only one way to move from one cell to the other. There is a hook at each cell‘s center. In the labyrinth there are two special free cells, such that if you can connect the hooks of those two cells with a rope, the labyrinth‘s secret door will be automatically opened. The problem is to prepare a shortest rope that can guarantee, you always can connect the hooks of those two cells with the prepared rope regardless their position in the labyrinth.

Input

The first line contains integers n and m (3 ≤ nm ≤ 820). The next lines describe the labyrinth. Each of the next m lines contains n characters. Each character is either "#" or ".", with "#" indicating an occupied cell, and "." indicating a free cell.

Output

Print out in the single line the length (measured in the number of cells) of the required rope.

Sample

inputoutput
7 6
#######
#.#.###
#.#.###
#.#.#.#
#.....#
#######
8
 

ural 1145. Rope in the Labyrinth

标签:

原文地址:http://www.cnblogs.com/StupidBoy/p/5077624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!