Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
s=[input() for _  in range(H)]
G=[["#"]*(W+2) for _ in range(H+2)]

for i in range(H):
    for j in range(W):
        G[i+1][j+1]=s[i][j]

def search(y,x):
    q=[(y,x)]
    d=[[-1]*(W+2) for _ in range(H+2)]
    d[y][x]=0
    while q:
        y1,x1=q.pop()
        for y2,x2 in ((y1+1,x1),(y1,x1+1),(y1-1,x1),(y1,x1-1)):
            if G[y2][x2]=="." and d[y2][x2]==-1:
                d[y2][x2]=d[y1][x1]+1
                q.append((y2,x2))
    return max(max(_) for _ in d)


for i in range(H):
    for j in range(W):
        if G[i+1][j+1]==".":
            ans=max(search(i+1,j+1),ans)

print(ans)

Fixed submission:
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
k=shortest_path(csr)
for i in range(f):   
    for q in range(f):
            if k[i][q]>=f+1:k[i][q]=-1

    ans=max(ans,max(k[i]))

print(int(ans))

Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
for i in range(H):
    for j in range(W): 
        cnt=W*i+j
        k=shortest_path(csr, indices=cnt)
        for q in range(f):
            if k[q]>=f+1:k[q]=-1
        ans=max(ans,max(k))

print(int(ans))

Fixed submission:
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
k=shortest_path(csr)
for i in range(f):   
    for q in range(f):
            if k[i][q]>=f+1:k[i][q]=-1

    ans=max(ans,max(k[i]))

print(int(ans))

Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
for i in range(H):
    for j in range(W): 
        cnt=W*i+j
        k=shortest_path(csr, indices=cnt)
        for q in range(f):
            if k[q]>=f+1:k[q]=-1
        ans=max(ans,max(k))

print(int(ans)

Fixed submission:
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
k=shortest_path(csr)
for i in range(f):   
    for q in range(f):
            if k[i][q]>=f+1:k[i][q]=-1

    ans=max(ans,max(k[i]))

print(int(ans))

Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
for i in range(H):
    for j in range(W): 
        cnt=W*i+j
        ans=max(ans,max(shortest_path(csr, indices=cnt)))

print(int(ans))

Fixed submission:
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
k=shortest_path(csr)
for i in range(f):   
    for q in range(f):
            if k[i][q]>=f+1:k[i][q]=-1

    ans=max(ans,max(k[i]))

print(int(ans))

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
s=["."]*h
for i in range(h):
    s[i]=input()
ans=0    
n=[[100]*h]*w
def check(i,j):
   
    n[i][j]=0   
    if 1<=j:
        if s[i][j-1]=="." and n[i][j-1]==100:
            check2(i,j-1)
    if j<=w-2:
        if s[i][j+1]=="." and n[i][j+1]==100:
            check2(i,j+1)
    if 1<=i:
        if s[i-1][j]=="." and n[i-1][j]==100:
            check2(i-1,j)
    if i<=h-2:
        if s[i+1][j]=="." and n[i+1][j]==100:
            check2(i+1,j)
    for i in range(h):
        for j in range(w):
            if n[i][j]==100:n[i][j]=0
           
    return max(max(n))

def check2(i,j):
    if 1<=j:n[i][j]=min(n[i][j],n[i][j-1])+1
    if j<=w-2:n[i][j]=min(n[i][j],n[i][j+1])+1
    if 1<=i:n[i][j]=min(n[i][j],n[i-1][j])+1
    if i<=h-2:n[i][j]=min(n[i][j],n[i+1][j])+1 
    if 1<=j:
        if s[i][j-1]=="." and n[i][j-1]==100:
            check2(i,j-1)
    if j<=w-2:
        if s[i][j+1]=="." and n[i][j+1]==100:
            check2(i,j+1)
    if 1<=i:
        if s[i-1][j]=="." and n[i-1][j]==100:
            check2(i-1,j)
    if i<=h-2:
        if s[i+1][j]=="." and n[i+1][j]==100:
            check2(i+1,j)
    
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            a=check(i,j)
            ans=max(ans,a)
print(ans-1)

Fixed submission:
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
k=shortest_path(csr)
for i in range(f):   
    for q in range(f):
            if k[i][q]>=f+1:k[i][q]=-1

    ans=max(ans,max(k[i]))

print(int(ans))