Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c == '.' for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if not A[y][x]:
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()

        ret = max(ret, n)
        if 0 < x and A[y][x-1]:
            Q.append((x-1, y, n+1))
            A[y][x-1] = False

        if x+1 < w and A[y][x+1]:
            Q.append((x+1, y, n+1))
            A[y][x+1] = False

        if 0 < y and A[y-1][x]:
            Q.append((x, y-1, n+1))
            A[y-1][x] = False

        if y+1 < h and A[y+1][x]:
            Q.append((x, y+1, n+1))
            A[y+1][x] = False

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Fixed submission:
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c == '.' for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if not A[y][x]:
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()

        ret = max(ret, n)
        if 0 < x and A[y][x-1]:
            Q.append((x-1, y, n+1))
            A[y][x-1] = False

        if x+1 < w and A[y][x+1]:
            Q.append((x+1, y, n+1))
            A[y][x+1] = False

        if 0 < y and A[y-1][x]:
            Q.append((x, y-1, n+1))
            A[y-1][x] = False

        if y+1 < h and A[y+1][x]:
            Q.append((x, y+1, n+1))
            A[y+1][x] = False

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if A[y][x] == '#':
                A[y][x] = '.'
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()
        if A[y][x] == '.':
            A[y][x] = '#'
            ret = max(ret, n)
            if 0 < x:
                Q.append((x-1, y, n+1))
            if x+1 < w:
                Q.append((x+1, y, n+1))
            if 0 < y:
                Q.append((x, y-1, n+1))
            if y+1 < h:
                Q.append((x, y+1, n+1))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Fixed submission:
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c == '.' for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if not A[y][x]:
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()

        ret = max(ret, n)
        if 0 < x and A[y][x-1]:
            Q.append((x-1, y, n+1))
            A[y][x-1] = False

        if x+1 < w and A[y][x+1]:
            Q.append((x+1, y, n+1))
            A[y][x+1] = False

        if 0 < y and A[y-1][x]:
            Q.append((x, y-1, n+1))
            A[y-1][x] = False

        if y+1 < h and A[y+1][x]:
            Q.append((x, y+1, n+1))
            A[y+1][x] = False

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if A[y][x] == '#':
                A[y][x] = '.'
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()
        if A[y][x] == '.':
            A[y][x] = '#'
            ret = max(ret, n)
            if 0 < x:
                Q.append((x-1, y, n+1))
            if x+1 < w:
                Q.append((x+1, y, n+1))
            if 0 < y:
                Q.append((x, y-1, n+1))
            if y+1 < h:
                Q.append((x, y+1, n+1))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Fixed submission:
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c == '.' for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if not A[y][x]:
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()

        ret = max(ret, n)
        if 0 < x and A[y][x-1]:
            Q.append((x-1, y, n+1))
            A[y][x-1] = False

        if x+1 < w and A[y][x+1]:
            Q.append((x+1, y, n+1))
            A[y][x+1] = False

        if 0 < y and A[y-1][x]:
            Q.append((x, y-1, n+1))
            A[y-1][x] = False

        if y+1 < h and A[y+1][x]:
            Q.append((x, y+1, n+1))
            A[y+1][x] = False

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))