Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue as queue

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = queue()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.put((i, j), False)
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while not q.empty():
        i, j = q.get(False)
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.put((ni, nj), False)
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()

Fixed submission:
from collections import deque

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = deque()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.append((i, j))
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while q:
        i, j = q.popleft()
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.append((ni, nj))
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue as queue

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = queue()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.put((i, j))
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while not q.empty():
        i, j = q.get()
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.put((ni, nj))
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()

Fixed submission:
from collections import deque

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = deque()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.append((i, j))
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while q:
        i, j = q.popleft()
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.append((ni, nj))
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()

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

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = deque()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.append((i, j))
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while q:
        i, j = q.popleft()
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.append((ni, nj))
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()

Fixed submission:
from collections import deque

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = deque()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.append((i, j))
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while q:
        i, j = q.popleft()
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.append((ni, nj))
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()