Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
import queue

def shortestpath(y0, x0):
    copymaze = deepcopy(maze)
    step_cnt = [[-1] * w for _ in range(h)]
    step_cnt[y0][x0] = 0
    q = queue.Queue()
    q.put((y0, x0))
    while not q.empty():
        y, x = q.get()
        copymaze[y][x] = '#'
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w and copymaze[y_next][x_next] == '.':
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                    
    return step_cnt[y][x]

h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]

max_steps = -1
for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] != '#':
            max_steps = max(max_steps, shortestpath(y0, x0))

print(max_steps)

Fixed submission:
import queue

def shortestpath(y0, x0):
    step_cnt = [[-1] * w for _ in range(h)]
    step_cnt[y0][x0] = 0
    q.put((y0, x0))
    while not q.empty():
        y, x = q.get()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w\
            and maze[y_next][x_next] == '.'\
            and step_cnt[y_next][x_next] == -1:
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                    
    return step_cnt[y][x]

h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = queue.Queue()

max_steps = -1
for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] != '#':
            max_steps = max(max_steps, shortestpath(y0, x0))

print(max_steps)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
import queue

def shortestpath(y0, x0, maze, h, w):
    step_cnt = [[-1] * w for _ in range(h)]
    q = queue.Queue()
    step_cnt[y0][x0] = 0
    q.put((y0, x0))
    dy = [-1, 0, 1, 0]
    dx = [0, -1, 0, 1]
    while not q.empty():
        y, x = q.get()
        maze[y][x] = '#'
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w and maze[y_next][x_next] == '.':
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                    
    return step_cnt[y][x]
 
h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
max_steps = -1

for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] == '#':
            continue
        copymaze = deepcopy(maze)
        max_steps = max(max_steps, shortestpath(y0, x0, copymaze, h, w))

print(max_steps)

Fixed submission:
import queue

def shortestpath(y0, x0):
    step_cnt = [[-1] * w for _ in range(h)]
    step_cnt[y0][x0] = 0
    q.put((y0, x0))
    while not q.empty():
        y, x = q.get()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w\
            and maze[y_next][x_next] == '.'\
            and step_cnt[y_next][x_next] == -1:
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                    
    return step_cnt[y][x]

h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = queue.Queue()

max_steps = -1
for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] != '#':
            max_steps = max(max_steps, shortestpath(y0, x0))

print(max_steps)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
import queue

def shortestpath(start, goal, maze, h, w):
    y1, x1 = start
    y2, x2 = goal
    if maze[y1][x1] == '#' or maze[y2][x2] == '#':
        return -1
    if start == goal:
        return -1
    
    step_cnt = [[-1] * w for _ in range(h)]
    q = queue.Queue()
    step_cnt[y1][x1] = 0
    q.put((y1, x1))
    dy = [-1, 0, 1, 0]
    dx = [0, -1, 0, 1]
    while not q.empty():
        y, x = q.get()
        maze[y][x] = '#'
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w and maze[y_next][x_next] == '.':
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                if y_next == y2 and x_next == x2:
                    return step_cnt[y2][x2]
                    
    return -1

h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
max_steps = -1

for y1 in range(h):
    for x1 in range(w):
        for y2 in range(y1, h):
            for x2 in range(w):
                copymaze = deepcopy(maze)
                max_steps = max(max_steps, shortestpath((y1,x1), (y2,x2), copymaze, h, w))

print(max_steps)

Fixed submission:
import queue

def shortestpath(y0, x0):
    step_cnt = [[-1] * w for _ in range(h)]
    step_cnt[y0][x0] = 0
    q.put((y0, x0))
    while not q.empty():
        y, x = q.get()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w\
            and maze[y_next][x_next] == '.'\
            and step_cnt[y_next][x_next] == -1:
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                    
    return step_cnt[y][x]

h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = queue.Queue()

max_steps = -1
for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] != '#':
            max_steps = max(max_steps, shortestpath(y0, x0))

print(max_steps)