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

h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

ans = 0
dx = [1,0,-1,0]
dy = [0,1,0,-1]

def bfs(y,x):
    global ans
    c = tmp_field[y][x]
    for k in range(4):
        newy = y + dy[k]
        newx = x + dx[k]
        if 0<= newy < h and 0<= newx < w:
            if field[newy][newx] == "#":
                ans = max(ans,c+1)
                q.clear()
                break
            elif tmp_field[newy][newx] == 0:
                tmp_field[newy][newx] = c+1
                q.append((newy,newx))

for i in range(h):
    for j in range(w):
        if field[i][j] == ".":
            tmp_field = [[0]*w for _ in range(h)]
            q = collections.deque([])
            q.append((i,j))
            while q:
                s = q.popleft()
                y,x =  s[0],s[1]
                bfs(y,x)
print(ans)

Fixed submission:
import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1

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

h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

ans = 0
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    for j in range(w):
        if field[i][j] == ".":
            tmp_field = [[0]*w for _ in range(h)]
            q = collections.deque([])
            q.append((i,j))
            while q:
                s = q.popleft()
                y,x =  s[0],s[1]
                c = tmp_field[y][x]
                for k in range(4):
                    newy = y + dy[k]
                    newx = x + dx[k]
                    if 0<= newy < h and 0<= newx < w:
                        if field[newy][newx] == "#":
                            ans = max(ans,c+1)
                            break
                        elif tmp_field[newy][newx] == 0:
                            tmp_field[newy][newx] = c+1
                            q.append((newy,newx))
                else:
                    continue
                break
print(ans)

Fixed submission:
import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1

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

h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

ans = 0
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    for j in range(w):
        if field[i][j] == ".":
            tmp_field = [[0]*w for _ in range(h)]
            q = collections.deque([])
            q.append((i,j))
            while q:
                s = q.popleft()
                y,x =  s[0],s[1]
                c = tmp_field[y][x]
                for k in range(4):
                    newy = y + dy[k]
                    newx = x + dx[k]
                    if 0<= newy < h and 0<= newx < w:
                        if field[newy][newx] == "#":
                            ans = max(ans,c+1)
                            break
                        elif tmp_field[newy][newx] == 0:
                            tmp_field[newy][newx] = c+1
                            q.append((newy,newx))
                else:
                    continue
                break
print(ans)

Fixed submission:
import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1

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

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1

Fixed submission:
import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1

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

h,w = map(int,input().split())

tizu = []
for i in range(h):
    s = list(input())
    tizu.append(s)

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    flag = False
    l = len(q)
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
        #tizu[yx[0]][yx[1]] = "#"
        flag = True
    if flag == False:
        print(ans-1)
        exit()
    ans += 1

Fixed submission:
import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1

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

h,w = map(int,input().split())

tizu = []
for i in range(h):
    s = list(input())
    tizu.append(s)

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
            
q = collections.deque()
ans = 0
while True:
    flag = False
    for i in range(h): 
        for k in range(w):
            if tizu[i][k] == "#":
                f(i,k)

    while q:
        yx = q.popleft()
        tizu[yx[0]][yx[1]] = "#"
        flag = True
   
    if flag == False:
        print(ans)
        exit()
    ans += 1


Fixed submission:
import collections

h,w = map(int,input().split())
tizu = [list(input()) for i in range(h)]

dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    l = len(q)
    if l == 0:
        print(ans-1)
        exit()
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
    ans += 1