Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
S = [input() for i in range(h)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=h*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][h*ni+nj] = 1

# print(N)

# for k in range(m):
#     for i in range(m):
#         for j in range(m):
#             N[i][j] = min(N[i][j], N[i][k]+N[k][j])

N = floyd_warshall(N)


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(int(ans))

Fixed submission:
h,w = map(int,input().split())
S = [input() for i in range(h)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=w*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][w*ni+nj] = 1

# print(N)

# for k in range(m):
#     for i in range(m):
#         for j in range(m):
#             N[i][j] = min(N[i][j], N[i][k]+N[k][j])

N = floyd_warshall(N)


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(int(ans))

Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
S = [input() for i in range(h)]

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=h*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][h*ni+nj] = 1

# print(N)

for k in range(m):
    for i in range(m):
        for j in range(m):
            N[i][j] = min(N[i][j], N[i][k]+N[k][j])


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(ans)

Fixed submission:
h,w = map(int,input().split())
S = [input() for i in range(h)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=w*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][w*ni+nj] = 1

# print(N)

# for k in range(m):
#     for i in range(m):
#         for j in range(m):
#             N[i][j] = min(N[i][j], N[i][k]+N[k][j])

N = floyd_warshall(N)


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(int(ans))