Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
A=[[0]*W for _ in range(H)]
ans=[]

for i in range(H):
    for j in range(W):
        c=0
        sy=i
        sx=j
        A[i][j]=1
        route=deque([(sy,sx,0)])
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]=='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
        ans.append(c)

print(max(ans))
                        

Fixed submission:
from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
A=[[0]*W for _ in range(H)]
ans=[]

for i in range(H):
    for j in range(W):
        sy=i
        sx=j
        if S[i][j]=='#':
            continue
        A[i][j]=1
        route=deque([(sy,sx,0)])
        while route:
            B=[]
            a,b,n=route.popleft()
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]=='#'
                    B.append(n)
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
        ans.append(max(B))

print(max(ans))
                   

Fixed submission:
from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
A=[[0]*W for _ in range(H)]
ans=[]

for i in range(H):
    for j in range(W):
        sy=i
        sx=j
        if S[i][j]=='#':
            continue
        A[i][j]=1
        for k in range(H):
            for l in range(W):
                ey=k
                ex=l
                if S[k][l]=='#':
                    continue
                if A[ey][ex]==1:
                    continue
                route=deque([(sy,sx,0)])
                while route:
                    a,b,n=route.popleft()
                    if a==ey and b==ex:
                        ans.append(n)
                        break
                    if 0<=a<=H-1 and 0<=b<=W-1:
                        if S[a][b]=='.':
                            S[a][b]=='#'
                            route.append((a+1,b,n+1))
                            route.append((a-1,b,n+1))
                            route.append((a,b+1,n+1))
                            route.append((a,b-1,n+1))

print(max(ans))      

Fixed submission:
from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]

ans=[]

for i in range(H):
    for j in range(W):
        sy=i
        sx=j
        if S[i][j]=='#':
            continue
        for k in range(H):
            for l in range(W):
                ey=k
                ex=l
                if S[k][l]=='#':
                    continue
                route=deque([(sy,sx,0)])
                while route:
                    a,b,n=route.popleft()
                    if a==ey and b==ex:
                        ans.append(n)
                        break
                    if 0<=a<=H-1 and 0<=b<=W-1:
                        if S[a][b]=='.':
                            S[a][b]=='#'
                            route.append((a+1,b,n+1))
                            route.append((a-1,b,n+1))
                            route.append((a,b+1,n+1))
                            route.append((a,b-1,n+1))

print(max(ans))

Fixed submission:
from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]

ans=[]

for i in range(H):
    for j in range(W):
        sy=i
        sx=j
        for k in range(H):
            for l in range(W):
                ey=k
                ex=l
                route=deque([(sy,sx,0)])
                while route:
                    a,b,n=route.popleft()
                    if a==ey and b==ex:
                        ans.append(n)
                        break
                    if 0<=a<=H-1 and 0<=b<=W-1:
                        if S[a][b]=='.':
                            S[a][b]=='#'
                            route.append((a+1,b,n+1))
                            route.append((a-1,b,n+1))
                            route.append((a,b+1,n+1))
                            route.append((a,b-1,n+1))

print(max(ans))

Fixed submission:
from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]

ans=[]

for i in range(H):
    for j in range(W):
        sy=i
        sx=j
        for k in range(H):
            for l in range(W):
                ey=k
                ex=l
                route=deque([(sy,sx,0)])
                while route:
                    a,b,n=route.popleft()
                    if a==ey and b==ex:
                        ans.append(n)
                        break
                    if 0<=a<=H-1 and 0<=b<=W-1:
                        if S[a][b]=='.':
                            S[a][b]=='#'
                            route.append((a+1,b,n+1))
                            route.append((a-1,b,n+1))
                            route.append((a,b+1,n+1))
                            route.append((a,b-1,n+1))

print(max(ans))

Fixed submission:
from collections import deque
import copy
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
S1=copy.deepcopy(S)
ans=[]

sy=0
sx=0
for i in range(H):
    for j in range(W):
        c=0
        route=deque([(i,j,0)])
        S=copy.deepcopy(S1)
        while route:
            a,b,n=route.popleft()
            c=n
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
                    
        ans.append(c-1)

print(max(ans))