Buggy python submission (verdict: Runtime Error):
# BFS
from collections import deque
import numpy as np


def main():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    # 頂点数と辺数
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    # 全頂点を未訪問に初期化
    dist = [[-1] * W for _ in range(H)]

    ans = float('inf')
    que = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append([h, w])
                dist[h][w] = 0

    # bfs開始 (キューが空になるまで探索を行う)
    while len(que) > 0:
        v = que.popleft()  # キューから先頭頂点を取り出す
        for i in range(4):
            nx = v[0] + dx[i]
            ny = v[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and dist[nx][ny] == -1):
                que.append([nx, ny])
                dist[nx][ny] = dist[v[0]][v[1]] + 1
    print(np.max(dist))


if __name__ == "__main__":
    main()


Fixed submission:
# BFS
from collections import deque


def main():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    # 頂点数と辺数
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    # 全頂点を未訪問に初期化
    dist = [[-1] * W for _ in range(H)]

    ans = float('inf')
    que = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append([h, w])
                dist[h][w] = 0

    # bfs開始 (キューが空になるまで探索を行う)
    while len(que) > 0:
        v = que.popleft()  # キューから先頭頂点を取り出す
        for i in range(4):
            nx = v[0] + dx[i]
            ny = v[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and dist[nx][ny] == -1):
                que.append([nx, ny])
                dist[nx][ny] = dist[v[0]][v[1]] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# BFS
from collections import deque
import numpy as np


def main():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    # 頂点数と辺数
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    # 全頂点を未訪問に初期化
    dist = [[-1] * W for _ in range(H)]

    ans = float('inf')
    que = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append([h, w])
                dist[h][w] = 0

    # bfs開始 (キューが空になるまで探索を行う)
    while len(que) > 0:
        v = que.popleft()  # キューから先頭頂点を取り出す
        for i in range(4):
            nx = v[0] + dx[i]
            ny = v[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and dist[nx][ny] == -1):
                que.append([nx, ny])
                dist[nx][ny] = dist[v[0]][v[1]] + 1
    print(np.max(dist))


if __name__ == "__main__":
    main()


Fixed submission:
# BFS
from collections import deque


def main():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    # 頂点数と辺数
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    # 全頂点を未訪問に初期化
    dist = [[-1] * W for _ in range(H)]

    ans = float('inf')
    que = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append([h, w])
                dist[h][w] = 0

    # bfs開始 (キューが空になるまで探索を行う)
    while len(que) > 0:
        v = que.popleft()  # キューから先頭頂点を取り出す
        for i in range(4):
            nx = v[0] + dx[i]
            ny = v[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and dist[nx][ny] == -1):
                que.append([nx, ny])
                dist[nx][ny] = dist[v[0]][v[1]] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# BFS
from collections import deque
import numpy as np
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
# 頂点数と辺数
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
# 全頂点を未訪問に初期化
dist = [[-1] * W for _ in range(H)]

ans = float('inf')
que = deque()
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            que.append([h, w])
            dist[h][w] = 0

# bfs開始 (キューが空になるまで探索を行う)
while len(que) > 0:
    v = que.popleft()  # キューから先頭頂点を取り出す
    for i in range(4):
        nx = v[0] + dx[i]
        ny = v[1] + dy[i]
        if (0 <= nx and nx < H and 0 <= ny and ny < W and A[nx][ny] != '#' and dist[nx][ny] == -1):
            que.append([nx, ny])
            dist[nx][ny] = dist[v[0]][v[1]] + 1
print(np.max(dist))

Fixed submission:
# BFS
from collections import deque


def main():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    # 頂点数と辺数
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    # 全頂点を未訪問に初期化
    dist = [[-1] * W for _ in range(H)]

    ans = float('inf')
    que = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append([h, w])
                dist[h][w] = 0

    # bfs開始 (キューが空になるまで探索を行う)
    while len(que) > 0:
        v = que.popleft()  # キューから先頭頂点を取り出す
        for i in range(4):
            nx = v[0] + dx[i]
            ny = v[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and dist[nx][ny] == -1):
                que.append([nx, ny])
                dist[nx][ny] = dist[v[0]][v[1]] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)


if __name__ == "__main__":
    main()