Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = []
for i in range(H):
    L.append(input())
import collections
q = collections.deque()
li = ((1,0),(0,1),(-1,0),(0,-1))
LL=[]

for i in range(H):
    for j in range(W):
        visited = [[-1]*W for i in range(H)]
        if L[i][j] ==".":
            visited[i][j] = 0
            q.append((i,j))
            cnt = 0
        
        while q:
            x,y = q.popleft()
            for dx,dy in li:
                nx,ny = x+dx,y+dy
                #print(nx,ny)
                if nx<0 or nx>=H or ny<0 or ny>=W or visited[nx][ny] >0:
                    continue
                if visited[nx][ny] ==-1 and  L[nx][ny] == ".": 
                    visited[nx][ny] = visited[x][y] +1
                    cnt = max(cnt,visited[nx][ny])
                    q.append((nx,ny))
                    print(q,cnt)
        LL.append(cnt)
print(max(LL))

Fixed submission:
import collections
H,W = map(int,input().split())
if H == W == 1:
    print(0)
    exit()
if (H == 1 and W == 2) or (H == 2 and W == 1):
    print(1)
    exit()
LL=[]
for i in range(H):
    LL.append(input())

L = ((1,0),(0,1),(-1,0),(0,-1))
q = collections.deque()
max_L = []
for i in range(H):
    for j in range(W):
        d = [[0]*W for i in range(H)]
        if LL[i][j] ==".":
            q.append((i,j))
            d[i][j] = 0
            max1 = 0
            while q:
                x,y = q.popleft()
                for dx,dy in L:
                    if 0>x+dx or x+dx>H-1 or 0>y+dy or y+dy>W-1 or d[x+dx][y+dy] !=0:
                        continue
                    if  LL[x+dx][y+dy] == ".":
                        d[x+dx][y+dy] = d[x][y] +1
                        q.append((x+dx,y+dy))
                        max1 = max(max1,d[x+dx][y+dy])
                        max_L.append(max1)
                        #print(q,d ,max1)
print(max(max_L))

Buggy python submission (verdict: Runtime Error):
import collections
q = collections.deque()
li = ((1,0),(0,1),(-1,0),(0,-1))
LL=[]

for i in range(H):
    for j in range(W):
        visited = [[-1]*W for i in range(H)]
        if L[i][j] ==".":
            visited[i][j] = 0
            q.append((i,j))
            cnt = 0
        
        while q:
            x,y = q.popleft()
            for dx,dy in li:
                nx,ny = x+dx,y+dy
                #print(nx,ny)
                if nx<0 or nx>=H or ny<0 or ny>=W or visited[nx][ny] >0:
                    continue
                if visited[nx][ny] ==-1 and  L[nx][ny] == ".": 
                    visited[nx][ny] = visited[x][y] +1
                    cnt = max(cnt,visited[nx][ny])
                    q.append((nx,ny))
        LL.append(cnt)
print(max(LL))

Fixed submission:
import collections
H,W = map(int,input().split())
if H == W == 1:
    print(0)
    exit()
if (H == 1 and W == 2) or (H == 2 and W == 1):
    print(1)
    exit()
LL=[]
for i in range(H):
    LL.append(input())

L = ((1,0),(0,1),(-1,0),(0,-1))
q = collections.deque()
max_L = []
for i in range(H):
    for j in range(W):
        d = [[0]*W for i in range(H)]
        if LL[i][j] ==".":
            q.append((i,j))
            d[i][j] = 0
            max1 = 0
            while q:
                x,y = q.popleft()
                for dx,dy in L:
                    if 0>x+dx or x+dx>H-1 or 0>y+dy or y+dy>W-1 or d[x+dx][y+dy] !=0:
                        continue
                    if  LL[x+dx][y+dy] == ".":
                        d[x+dx][y+dy] = d[x][y] +1
                        q.append((x+dx,y+dy))
                        max1 = max(max1,d[x+dx][y+dy])
                        max_L.append(max1)
                        #print(q,d ,max1)
print(max(max_L))