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):
import copy
import numpy as np
from collections import deque
m,n = list(map(int, input().split()))
o2 = []
dist_mat = []
for i in range(m):
    o1 = list(str(input()))
    o2.append(o1)
    dist_mat.append(np.zeros(len(o1)))

in_mat = np.array(o2)

dist_mat = []
for i in in_mat:
    dist_mat.append(np.zeros(len(i)))
dist_mat = np.array(dist_mat)
rows,cols = dist_mat.shape

qu = deque()

for r in range(rows):
    for c in range(cols):
        if in_mat[r][c] == ".":
            qu.appendleft((r,c))

dist_mat_base = copy.deepcopy(dist_mat)

ans = []
lenqu = len(qu)
for i in range(lenqu):
    print(i)
    strt = qu.pop()
    qu2 = deque()
    qu2.appendleft(strt)
    dist_mat = copy.deepcopy(dist_mat_base)

    while qu2:
        curr_r, curr_c = qu2.pop()
        dist = dist_mat[curr_r][curr_c]
        adj_cells = [(0,1), (1,0), (0,-1), (-1,0)]
        for r_adj, c_adj in adj_cells:
            adj_row = curr_r + r_adj
            adj_col = curr_c + c_adj
            if 0 <= adj_row < rows and 0 <= adj_col < cols:
                if dist_mat[adj_row][adj_col] == 0 and in_mat[adj_row][adj_col] == "." and not (adj_row, adj_col) == strt:
                    dist_mat[adj_row][adj_col] = dist + 1
                    qu2.appendleft((adj_row, adj_col))

    dist_vec = np.concatenate(dist_mat)
    ans.append(round(max(dist_vec)))

print(round(max(ans)))

import copy
import numpy as np
from collections import deque
m,n = list(map(int, input().split()))
o2 = []
dist_mat = []
for i in range(m):
    o1 = list(str(input()))
    o2.append(o1)
    dist_mat.append(np.zeros(len(o1)))

in_mat = np.array(o2)

dist_mat = []
for i in in_mat:
    dist_mat.append(np.zeros(len(i)))
dist_mat = np.array(dist_mat)
rows,cols = dist_mat.shape

qu = deque()

for r in range(rows):
    for c in range(cols):
        if in_mat[r][c] == ".":
            qu.appendleft((r,c))

dist_mat_base = copy.deepcopy(dist_mat)

ans = []
lenqu = len(qu)
for i in range(lenqu):
    strt = qu.pop()
    qu2 = deque()
    qu2.appendleft(strt)
    dist_mat = copy.deepcopy(dist_mat_base)

    while qu2:
        curr_r, curr_c = qu2.pop()
        dist = dist_mat[curr_r][curr_c]
        adj_cells = [(0,1), (1,0), (0,-1), (-1,0)]
        for r_adj, c_adj in adj_cells:
            adj_row = curr_r + r_adj
            adj_col = curr_c + c_adj
            if 0 <= adj_row < rows and 0 <= adj_col < cols:
                if dist_mat[adj_row][adj_col] == 0 and in_mat[adj_row][adj_col] == "." and not (adj_row, adj_col) == strt:
                    dist_mat[adj_row][adj_col] = dist + 1
                    qu2.appendleft((adj_row, adj_col))

    dist_vec = np.concatenate(dist_mat)
    ans.append(round(max(dist_vec)))

print(int(max(ans)))

Verdicts: Wrong Answer

Accepted