Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = np.array([c == "." for c in "".join(input() for _ in range(H))], dtype=np.bool)
array = np.zeros((H * W, H * W), dtype=np.bool)
N = np.arange(H * W)
R, C = np.divmod(N, W)
c_i = N[maze[N] & (C > 0) & maze[N - 1]]
r_i = N[maze[N] & (R > 0) & maze[N - W]]
array[c_i, c_i - 1] = 1
array[c_i - 1, c_i] = 1
array[r_i, r_i - W] = 1
array[r_i - W, r_i] = 1
dist = csgraph.shortest_path(array)
print(int(dist[dist < 401].max()))


Fixed submission:
import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(array, directed=False)
print(int(dist[dist < 401].max()))

Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(csr_matrix(array, dtype=np.bool, shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))

Fixed submission:
import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(array, directed=False)
print(int(dist[dist < 401].max()))

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix, csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
data = []
row = []
column = []
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n - 1)
    if c != W - 1 and maze[n + 1] == ".":
        data.append(1)
        row.append(n)
        column.append(n + 1)
    if r and maze[n - W] == ".":
        data.append(1)
        row.append(n)
        column.append(n - W)
    if r != H - 1 and maze[n + W] == ".":
        data.append(1)
        row.append(n)
        column.append(n + W)
dist = csgraph.shortest_path(csr_matrix((data, (row, column)), dtype="i8", shape=(H * W, H * W)), directed=False)
print(int(dist[dist < 401].max()))

Fixed submission:
import numpy as np
from scipy.sparse import csgraph
H, W = map(int, input().split())
maze = "".join(input() for _ in range(H))
array = np.zeros((H * W, H * W), dtype=np.bool)
for n in range(H * W):
    if maze[n] == "#":
        continue
    r, c = divmod(n, W)
    if c and maze[n - 1] == ".":
        array[n][n - 1] = 1
    if c != W - 1 and maze[n + 1] == ".":
        array[n][n + 1] = 1
    if r and maze[n - W] == ".":
        array[n][n - W] = 1
    if r != H - 1 and maze[n + W] == ".":
        array[n][n + W] = 1
dist = csgraph.shortest_path(array, directed=False)
print(int(dist[dist < 401].max()))