Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} 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.

Submission attempts (in order):
from collections import deque
h,w = map(int,input().split())
s = [0]*(h+2)
s[0]  = ["#"]*(w+2)
s[-1] = ["#"]*(w+2)
for i in range(h):
    s[i+1] = ["#"] + list(input()) + ["#"]
ans = 0
for i in range(h+2):
    for j in range(w+2):
        if s[i][j] == "#":
            pass
        else:
            xs,ys = j,i
            print(xs,ys)
            qx = deque([])
            qx.append(xs)
            qy = deque([])
            qy.append(ys)
            reach = [[0 for j in range(w+2)] for i in range(h+2)]
            reach[ys][xs] = 1
            while qx:
                x = qx.popleft()
                y = qy.popleft()

                if s[y-1][x] == "." and reach[y-1][x] == 0:
                    qx.append(x)
                    qy.append(y-1)
                    reach[y-1][x] = reach[y][x] + 1
                if s[y+1][x] == "." and reach[y+1][x] == 0:
                    qx.append(x)
                    qy.append(y+1)
                    reach[y+1][x] = reach[y][x] + 1
                if s[y][x-1] == "." and reach[y][x-1] == 0:
                    qx.append(x-1)
                    qy.append(y)
                    reach[y][x-1] = reach[y][x] + 1
                if s[y][x+1] == "." and reach[y][x+1] == 0:
                    qx.append(x+1)
                    qy.append(y)
                    reach[y][x+1] = reach[y][x] + 1
            m = 0
            for i in range(h+2):
                m = max(m,max(reach[i][:])-1)
            ans = max(ans,m)
print(ans)

from collections import deque
h,w = map(int,input().split())
s = [0]*(h+2)
s[0]  = ["#"]*(w+2)
s[-1] = ["#"]*(w+2)
for i in range(h):
    s[i+1] = ["#"] + list(input()) + ["#"]
ans = 1
for i in range(h+2):
    for j in range(w+2):
        if s[i][j] != ".":
            pass
        else:
            xs,ys = j,i
            qx = deque([])
            qx.append(xs)
            qy = deque([])
            qy.append(ys)
            reach = [[0 for _1 in range(w+2)] for _2 in range(h+2)]
            reach[ys][xs] = 1
            while qx:
                x = qx.popleft()
                y = qy.popleft()

                if s[y-1][x] == "." and reach[y-1][x] == 0:
                    qx.append(x)
                    qy.append(y-1)
                    reach[y-1][x] = reach[y][x] + 1
                if s[y+1][x] == "." and reach[y+1][x] == 0:
                    qx.append(x)
                    qy.append(y+1)
                    reach[y+1][x] = reach[y][x] + 1
                if s[y][x-1] == "." and reach[y][x-1] == 0:
                    qx.append(x-1)
                    qy.append(y)
                    reach[y][x-1] = reach[y][x] + 1
                if s[y][x+1] == "." and reach[y][x+1] == 0:
                    qx.append(x+1)
                    qy.append(y)
                    reach[y][x+1] = reach[y][x] + 1
            m = 1
            for k in range(h+2):
                m = max(m,max(reach[k][:])-1)
            ans = max(ans,m)
print(ans)

Verdicts: Wrong Answer

Accepted