Buggy python submission (verdict: Time Limit Exceeded):
import collections
INF = 10**18
def bfs(starth,startw):
    d = [[-1]*w for i in range(h)]
    d[starth][startw] = 0
    q = collections.deque([])
    q.append((starth,startw))
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    while q:
        p = q.popleft()
        nowh = p[0]
        noww = p[1]
        for i in range(4):
            nexth = nowh + dy[i]
            nextw = noww + dx[i]
            if 0<=nextw<w and 0<=nexth<h:
                if d[nexth][nextw] == -1 and li[nexth][nextw] != "#":
                    q.append([nexth,nextw])
                    d[nexth][nextw] = d[nowh][noww] + 1
    return d
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
cost = [[INF]*w for i in range(h)]
koho = []
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            koho.append([i,j])
for i in range(len(koho)):
    starth = koho[i][0]
    startw = koho[i][1]
    a = bfs(starth,startw)
    for j in range(h):
        for k in range(w):
            cost[j][k] = min(cost[j][k],a[j][k])

ans = -1
for i in range(h):
    for j in range(w):
        ans = max(cost[i][j],ans)
print(ans)


Fixed submission:
import collections
INF = 10**18
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
koho = []
d = [[-1]*w for i in range(h)]
q = collections.deque([])
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            d[i][j] = 0
            q.append([i,j])
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while q:
    p = q.popleft()
    y = p[0]
    x = p[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx<w and 0<=ny<h:
            if d[ny][nx] == -1:
                q.append([ny,nx])
                d[ny][nx] = d[y][x] + 1
ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans,d[i][j])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
INF = 10**18
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
koho = []
d = [[-1]*w for i in range(h)]
q = collections.deque([])
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            d[i][j] = 0
            q.append([i,j])
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while q:
    p = q.popleft()
    y = p[0]
    x = p[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx<w and 0<=ny<h:
            if d[ny][nx] == -1:
                q.append([ny,nx])
                d[ny][nx] = d[y][x] + 1
ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans,d[i][j])
print(ans)

Fixed submission:
import collections
INF = 10**18
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
koho = []
d = [[-1]*w for i in range(h)]
q = collections.deque([])
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            d[i][j] = 0
            q.append([i,j])
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while q:
    p = q.popleft()
    y = p[0]
    x = p[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx<w and 0<=ny<h:
            if d[ny][nx] == -1:
                q.append([ny,nx])
                d[ny][nx] = d[y][x] + 1
ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans,d[i][j])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
INF = 10**18
def bfs(starth,startw):
    d = [[-1]*w for i in range(h)]
    d[starth][startw] = 0
    q = collections.deque([])
    q.append((starth,startw))
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    while q:
        p = q.popleft()
        nowh = p[0]
        noww = p[1]
        for i in range(4):
            nexth = nowh + dy[i]
            nextw = noww + dx[i]
            if 0<=nextw<w and 0<=nexth<h:
                if d[nexth][nextw] == -1 and li[nexth][nextw] != "#":
                    q.append([nexth,nextw])
                    d[nexth][nextw] = d[nowh][noww] + 1
    return d
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
cost = [[INF]*w for i in range(h)]
koho = []
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            koho.append([i,j])
for i in range(len(koho)):
    starth = koho[i][0]
    startw = koho[i][1]
    a = bfs(starth,startw)
    for j in range(h):
        for k in range(w):
            cost[j][k] = min(cost[j][k],a[j][k])

ans = -1
for i in range(h):
    for j in range(w):
        ans = max(cost[i][j],ans)
print(ans)

Fixed submission:
import collections
INF = 10**18
h,w = map(int,input().split())
li = [list(input()) for i in range(h)]
koho = []
d = [[-1]*w for i in range(h)]
q = collections.deque([])
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            d[i][j] = 0
            q.append([i,j])
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while q:
    p = q.popleft()
    y = p[0]
    x = p[1]
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx<w and 0<=ny<h:
            if d[ny][nx] == -1:
                q.append([ny,nx])
                d[ny][nx] = d[y][x] + 1
ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans,d[i][j])
print(ans)