선생님 코드
import sys
sys.stdin = open("input.txt", "rt")
from collections import deque
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
thru = [list(map(int,input().split())) for _ in range(7)]
dis = [[0]*7 for _ in range(7)]
Q = deque()
Q.append((0,0))
thru[0][0] = 1
while Q:
tmp = Q.popleft()
for i in range(4):
for i in range(4):
x = tmp + dx[i]
y = tmp + dy[i]
if 0 <=x <=6 and 0 <=y <=6 and thru[x][y]==0:
thru[x][y] = 1
dis[x][y] = dis[tmp[0]][tmp[1]]+1
Q.append((x,y))
if dis[6][6]==0:
print(-1)
else:
print(dis[6][6])