Buggy python submission (verdict: Time Limit Exceeded):
#darker　and darker
from collections import deque
d=deque()
e=deque()
h,w=map(int,input().split())
field=[0 for i in range(h+2)]
field[0]=[True for i in range(w+2)]
distance=0
for i in range(h):
    s=input()
    a=[False for i in range(w+2)]
    a[0]=True
    for j in range(w):
        if s[j]=="#":
            a[j+1]=True
            d.append((i+1,j+1))
    a[w+1]=True
    field[i+1]=a
field[h+1]=[True for i in range(w+2)]
while d:
    while d:
        some=d.popleft()
        index1,index2=some[0],some[1]
        if field[index1-1][index2]==False:
                field[index1-1][index2]=True
                e.append((index1-1,index2))
        if field[index1+1][index2]==False:
                field[index1+1][index2]=True
                e.append((index1+1,index2))
        if field[index1][index2+1]==False:
                field[index1][index2+1]=True
                e.append((index1,index2+1))
        if  field[index1][index2-1]==False:
                field[index1][index2-1]=True
                e.append((index1,index2-1))
    distance+=1
    d=e
    e=deque()
print(distance-1)
    

Fixed submission:
#darker　and darker
from collections import deque
d=deque()
e=deque()
h,w=map(int,input().split())
field=[0 for i in range(h+2)]
field[0]=[True for i in range(w+2)]
distance=0
for i in range(h):
    s=input()
    a=[False for i in range(w+2)]
    a[0]=True
    for j in range(w):
        if s[j]=="#":
            a[j+1]=True
            d.append((i+1,j+1))
    a[w+1]=True
    field[i+1]=a
field[h+1]=[True for i in range(w+2)]
while d:
    while d:
        some=d.popleft()
        index1,index2=some[0],some[1]
        if field[index1-1][index2]==False:
                field[index1-1][index2]=True
                e.append((index1-1,index2))
        if field[index1+1][index2]==False:
                field[index1+1][index2]=True
                e.append((index1+1,index2))
        if field[index1][index2+1]==False:
                field[index1][index2+1]=True
                e.append((index1,index2+1))
        if  field[index1][index2-1]==False:
                field[index1][index2-1]=True
                e.append((index1,index2-1))
    distance+=1
    d=e
    e=deque()
print(distance-1)

Buggy python submission (verdict: Time Limit Exceeded):
#darker　and darker
from collections import deque
d=deque()
e=deque()
h,w=map(int,input().split())
field=[0 for i in range(h+2)]
field[0]=[True for i in range(w+2)]
#visited_node=0
distance=0
for i in range(h):
    s=input()
    a=[]
    a.append(True)
    for j in range(w):
        if s[j]=="#":
            a.append(True)
            d.append((i+1,j+1))
        else:
            a.append(False)
    a.append(True)
    field[i+1]=a
field[h+1]=[True for i in range(w+2)]
while d:
    while d:
        some=d.popleft()
        index1,index2=some[0],some[1]
        if field[index1-1][index2]==False:
                field[index1-1][index2]=True
                e.append((index1-1,index2))
        if field[index1+1][index2]==False:
                field[index1+1][index2]=True
                e.append((index1+1,index2))
        if field[index1][index2+1]==False:
                field[index1][index2+1]=True
                e.append((index1,index2+1))
        if  field[index1][index2-1]==False:
                field[index1][index2-1]=True
                e.append((index1,index2-1))
    distance+=1
    d=e
    e=deque()
print(distance-1)
    

Fixed submission:
#darker　and darker
from collections import deque
d=deque()
e=deque()
h,w=map(int,input().split())
field=[0 for i in range(h+2)]
field[0]=[True for i in range(w+2)]
distance=0
for i in range(h):
    s=input()
    a=[False for i in range(w+2)]
    a[0]=True
    for j in range(w):
        if s[j]=="#":
            a[j+1]=True
            d.append((i+1,j+1))
    a[w+1]=True
    field[i+1]=a
field[h+1]=[True for i in range(w+2)]
while d:
    while d:
        some=d.popleft()
        index1,index2=some[0],some[1]
        if field[index1-1][index2]==False:
                field[index1-1][index2]=True
                e.append((index1-1,index2))
        if field[index1+1][index2]==False:
                field[index1+1][index2]=True
                e.append((index1+1,index2))
        if field[index1][index2+1]==False:
                field[index1][index2+1]=True
                e.append((index1,index2+1))
        if  field[index1][index2-1]==False:
                field[index1][index2-1]=True
                e.append((index1,index2-1))
    distance+=1
    d=e
    e=deque()
print(distance-1)

Buggy python submission (verdict: Time Limit Exceeded):
#darker　and darker
from collections import deque
d=deque()
e=deque()
h,w=map(int,input().split())
field=[]
field.append([True for i in range(w+2)])
#visited_node=0
distance=0
for i in range(h):
    s=input()
    a=[]
    a.append(True)
    for j in range(w):
        if s[j]=="#":
            a.append(True)
            d.append((i+1,j+1))
        else:
            a.append(False)
    a.append(True)
    field.append(a)
field.append([True for i in range(w+2)])
while d:
    for some in d:
        index1,index2=some[0],some[1]
        if field[index1-1][index2]==False:
            field[index1-1][index2]=True
            e.append((index1-1,index2))
        if field[index1+1][index2]==False:
            field[index1+1][index2]=True
            e.append((index1+1,index2))
        if field[index1][index2+1]==False:
            field[index1][index2+1]=True
            e.append((index1,index2+1))
        if  field[index1][index2-1]==False:
            field[index1][index2-1]=True
            e.append((index1,index2-1))
    distance+=1
    d=e
    e=deque()
print(distance-1)

Fixed submission:
#darker　and darker
from collections import deque
d=deque()
e=deque()
h,w=map(int,input().split())
field=[0 for i in range(h+2)]
field[0]=[True for i in range(w+2)]
distance=0
for i in range(h):
    s=input()
    a=[False for i in range(w+2)]
    a[0]=True
    for j in range(w):
        if s[j]=="#":
            a[j+1]=True
            d.append((i+1,j+1))
    a[w+1]=True
    field[i+1]=a
field[h+1]=[True for i in range(w+2)]
while d:
    while d:
        some=d.popleft()
        index1,index2=some[0],some[1]
        if field[index1-1][index2]==False:
                field[index1-1][index2]=True
                e.append((index1-1,index2))
        if field[index1+1][index2]==False:
                field[index1+1][index2]=True
                e.append((index1+1,index2))
        if field[index1][index2+1]==False:
                field[index1][index2+1]=True
                e.append((index1,index2+1))
        if  field[index1][index2-1]==False:
                field[index1][index2-1]=True
                e.append((index1,index2-1))
    distance+=1
    d=e
    e=deque()
print(distance-1)