I'm writing a BFS-based code where the closest distance from the boxes marked 1 have to be calculated. The distance of the boxes marked 1 are 0.
This is a problem from Google kickstart 2019 round A: Parcels.
Link: https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050e01/000000000006987d
import time 
def multibfs (office, r, c):
    #office is a 2-D list with 0's and 1's
    visited = [[False]*c for x in range (r)] 
    values = [[1e9]*c for x in range (r)] #closest distance
    queue = [] #Bfs queue
    for i in range (r): 
        for j in range (c): 
            if office[i][j]==1: 
                visited[i][j]=True 
                values[i][j]=0 
                queue.append([i,j]) 
    while queue: 
        s = queue.pop(0)
        iPos = s[0]
        jPos = s[1]
        for i in range (iPos-1, iPos+2):
            if i in range (0, r): 
                if visited[i][jPos] == False:
                    queue.append([i, jPos])
                    visited[i][jPos] = True
                    values[i][jPos] = values[iPos][jPos] + 1
        for j in range (jPos-1, jPos+2):
            if j in range (0, c):
                if visited[iPos][j] == False:
                    queue.append([iPos, j])
                    visited[iPos][j] = True
                    values[iPos][j] = values[iPos][jPos] + 1
    return values 
tic=time.time() 
o = [[1]*250 for x in range (250)]
val = multibfs(o, 250, 250) 
print(time.time()-tic)
for r and c equal to 250, and office having only 1's, the execution time for python3.6 is roughly 0.7s. I expected the PyPy implementation to be much faster, but it takes much longer
