Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<H and 0<=ny<W:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue
ju=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(H):
    for j in range(W):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])
print(ans)



Fixed submission:
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<H and 0<=ny<W:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue
ju=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(H):
    for j in range(W):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<W and 0<=ny<H:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue

ju=[]

for i in range(W):
    for j in range(H):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(W):
    for j in range(H):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])

print(ans)



Fixed submission:
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<H and 0<=ny<W:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue
ju=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(H):
    for j in range(W):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[float('inf') for i in range(W)] for j in range(H)]

def bfs(sx,sy):
    tmp=deque([[sx,sy]])
    ch=[[False for i in range(W)] for j in range(H)]
    P=[[0 for i in range(W)] for j in range(H)]
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<W and 0<=ny<H:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    P[nx][ny]=P[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
    for i in range(W):
        for j in range(H):
            V[i][j]=min(P[i][j],V[i][j])

for i in range(W):
    for j in range(H):
        if A[i][j]=="#":
            bfs(i,j)

for i in range(W):
    for j in range(H):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])

print(ans)



Fixed submission:
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<H and 0<=ny<W:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue
ju=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(H):
    for j in range(W):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[float('inf') for i in range(W)] for j in range(H)]

def bfs(sx,sy):
    tmp=deque([[sx,sy]])
    ch=[[False for i in range(W)] for j in range(H)]
    P=[[0 for i in range(W)] for j in range(H)]
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<W and 0<=ny<H:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    P[nx][ny]=P[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
    for i in range(W):
        for j in range(H):
            V[i][j]=min(P[i][j],V[i][j])

for i in range(W):
    for j in range(H):
        if A[i][j]=="#":
            bfs(i,j)

for i in range(W):
    for j in range(H):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])

print(ans)



Fixed submission:
from collections import deque

H,W=map(int,input().split())
A=[input() for i in range(H)]
ans=0
V=[[0 for i in range(W)] for j in range(H)]

def bfs(q):
    tmp=deque(q)
    ch = [[False for i in range(W)] for j in range(H)]
    count = 0
    d=[[-1,0],[1,0],[0,-1],[0,1]]
    while tmp:
        x,y=tmp.popleft()
        for a,b in d:
            nx=x+a
            ny=y+b
            if 0<=nx<H and 0<=ny<W:
                if ch[nx][ny]!=True and A[nx][ny]==".":
                    V[nx][ny]=V[x][y]+1
                    ch[nx][ny]=True
                    tmp.append([nx,ny])
            else:
                continue
ju=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            ju.append([i,j])
bfs(ju)
for i in range(H):
    for j in range(W):
        if not A[i][j]=="#":
             ans=max(ans,V[i][j])
print(ans)