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

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            ss[y][x] = "#"
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
        m = max(m,max_cost)
print(m)

Fixed submission:
from collections import deque
from copy import deepcopy

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        ss[sy][sx] = "#"
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
                        ss[ny][nx] = "#"
        m = max(m,max_cost)
print(m)

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

h,w = map(int,input().split())
s = [input() for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        f = [[True]*w for i in range(h)]
        f[sy][sx] = False
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            f[y][x] = False
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if s[ny][nx] == "." and f[ny][nx]:
                        q.append((cost,ny,nx))
        m = max(m,max_cost)
print(m)

Fixed submission:
from collections import deque
from copy import deepcopy

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        ss[sy][sx] = "#"
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
                        ss[ny][nx] = "#"
        m = max(m,max_cost)
print(m)

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

h,w = map(int,input().split())
s = [input() for i in range(h)]
sy,sx = 0,0
f = False
for i,si in enumerate(s):
    if f:
        break
    for j,sij in enumerate(si):
        if sij == ".":
            sysx = i,j
            f = True
            break

t = ((0,1),(1,0),(-1,0),(0,-1))
c = 0
se = set()
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        f = [[True]*w for i in range(h)]
        f[sy][sx] = False
        while(q):
            cost,y,x = q.popleft()
            if max_cost < cost:
                max_cost = cost
                my,mx = y,x
            f[y][x] = False
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if s[ny][nx] == "." and f[ny][nx]:
                        q.append((cost,ny,nx))
        m = max(m,max_cost)
print(m)

Fixed submission:
from collections import deque
from copy import deepcopy

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        ss[sy][sx] = "#"
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
                        ss[ny][nx] = "#"
        m = max(m,max_cost)
print(m)

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

h,w = map(int,input().split())
s = [input() for i in range(h)]
sy,sx = 0,0
f = False
for i,si in enumerate(s):
    if f:
        break
    for j,sij in enumerate(si):
        if sij == ".":
            sysx = i,j
            f = True
            break

t = ((0,1),(1,0),(-1,0),(0,-1))
c = 0
se = set()
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        f = [[True]*w for i in range(h)]
        f[sy][sx] = False
        while(q):
            cost,y,x = q.popleft()
            if max_cost < cost:
                max_cost = cost
                my,mx = y,x
            f[y][x] = False
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if s[ny][nx] == "." and f[ny][nx]:
                        q.append((cost,ny,nx))
        m = max(m,max_cost)
print(m)

Fixed submission:
from collections import deque
from copy import deepcopy

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        ss[sy][sx] = "#"
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
                        ss[ny][nx] = "#"
        m = max(m,max_cost)
print(m)