Buggy python submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
if all(all(j=="#" for j in list(a)) for i in a):
    print(0)
else:
    result = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == ".":
                q = deque([[i, j]])
                visit = [[-1 for _ in range(w)] for __ in range(h)]
                visit[i][j] = 0
                check = False
                while q:
                    y, x = q.popleft()
                    for s, t in [[-1,0],[1,0],[0,-1],[0,1]]:
                        if 0<=y+s and y+s<h and 0<=x+t and x+t<w:
                            if a[y+s][x+t]=="#":
                                result.append(visit[y][x]+1)
                                
                            elif visit[y+s][x+t]<0:
                                visit[y+s][x+t] = visit[y][x]+1
                                q.append([y+s,x+t])
    print(max(result))

Fixed submission:
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
memo = [[-1 if j=="." else 0 for j in list(i)] for i in a]

q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            q.append([i, j])
q = deque(q)
while q:
    x, y = q.popleft()
    for s, t in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0<=x+s and 0<=y+t and x+s<h and y+t<w:
            if memo[x+s][y+t]<0:
                memo[x+s][y+t]=memo[x][y]+1
                q.append([x+s,y+t])
print(max(max(i) for i in memo))

Buggy python submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
if all(all(j=="." for j in list(a)) for i in a):
    print(0)
else:
    result = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == ".":
                q = deque([[i, j]])
                visit = [[-1 for _ in range(w)] for __ in range(h)]
                visit[i][j] = 0
                check = False
                while q:
                    y, x = q.popleft()
                    for s, t in [[-1,0],[1,0],[0,-1],[0,1]]:
                        if 0<=y+s and y+s<h and 0<=x+t and x+t<w:
                            if a[y+s][x+t]=="#":
                                result.append(visit[y][x]+1)
                                q = 0
                                break
                            elif visit[y+s][x+t]<0:
                                visit[y+s][x+t] = visit[y][x]+1
                                q.append([y+s,x+t])
    print(max(result))

Fixed submission:
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
memo = [[-1 if j=="." else 0 for j in list(i)] for i in a]

q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            q.append([i, j])
q = deque(q)
while q:
    x, y = q.popleft()
    for s, t in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0<=x+s and 0<=y+t and x+s<h and y+t<w:
            if memo[x+s][y+t]<0:
                memo[x+s][y+t]=memo[x][y]+1
                q.append([x+s,y+t])
print(max(max(i) for i in memo))

Buggy python submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
result = []
for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            q = deque([[i, j]])
            visit = [[-1 for _ in range(w)] for __ in range(h)]
            visit[i][j] = 0
            check = False
            while q:
                y, x = q.popleft()
                for s, t in [[-1,0],[1,0],[0,-1],[0,1]]:
                    if 0<=y+s and y+s<h and 0<=x+t and x+t<w:
                        if a[y+s][x+t]=="#":
                            result.append(visit[y][x]+1)
                            q = 0
                            break
                        elif visit[y+s][x+t]<0:
                            visit[y+s][x+t] = visit[y][x]+1
                            q.append([y+s,x+t])

print(max(result))

Fixed submission:
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
memo = [[-1 if j=="." else 0 for j in list(i)] for i in a]

q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            q.append([i, j])
q = deque(q)
while q:
    x, y = q.popleft()
    for s, t in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0<=x+s and 0<=y+t and x+s<h and y+t<w:
            if memo[x+s][y+t]<0:
                memo[x+s][y+t]=memo[x][y]+1
                q.append([x+s,y+t])
print(max(max(i) for i in memo))

Buggy python submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
result = []
for i in range(h):
    for j in range(w):
        if a[i][j] == ".":
            q = deque([[i, j]])
            visit = [[-1 for _ in range(w)] for __ in range(h)]
            visit[i][j] = 0
            check = False
            while q:
                y, x = q.popleft()
                for s, t in [[-1,0],[1,0],[0,-1],[0,1]]:
                    if 0<=y+s and y+s<h and 0<=x+t and x+t<w:
                        if a[y+s][x+t]=="#":
                            result.append(visit[y][x]+1)
                            q = 0
                            break
                        elif visit[y+s][x+t]<0:
                            visit[y+s][x+t] = visit[y][x]+1
                            q.append([y+s,x+t])

print(max(result))

Fixed submission:
from collections import deque
h, w = map(int, input().split())
a = [input() for _ in range(h)]
memo = [[-1 if j=="." else 0 for j in list(i)] for i in a]

q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            q.append([i, j])
q = deque(q)
while q:
    x, y = q.popleft()
    for s, t in [[1,0],[-1,0],[0,1],[0,-1]]:
        if 0<=x+s and 0<=y+t and x+s<h and y+t<w:
            if memo[x+s][y+t]<0:
                memo[x+s][y+t]=memo[x][y]+1
                q.append([x+s,y+t])
print(max(max(i) for i in memo))