100 atcoder#ABC151D. [ABC151D] Maze Master
[ABC151D] Maze Master
Score : points
Problem Statement
Takahashi has a maze, which is a grid of squares with horizontal rows and vertical columns.
The square at the -th row from the top and the -th column is a "wall" square if is #
, and a "road" square if is .
.
From a road square, you can move to a horizontally or vertically adjacent road square.
You cannot move out of the maze, move to a wall square, or move diagonally.
Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.
Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.
In this situation, find the maximum possible number of moves Aoki has to make.
Constraints
- is
.
or#
. - contains at least two occurrences of
.
. - Any road square can be reached from any road square in zero or more moves.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible number of moves Aoki has to make.
3 3
...
...
...
4
If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.
3 5
...#.
.#.#.
.#...
10
If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.