迷宫最短路
10 10
0 1
9 8
#S######.#
......#..#
.#.##.##.#
.#........
##.##.####
....#....#
.#######.#
....#.....
.####.###.
....#...G#
n,m=map(int,input().split())
sx,sy=map(int,input().split())
gx,gy=map(int,input().split())
maze=[]
vis=[[0]*m for i in range(n)]
for i in range(n):
list1=list(input())
maze.append(list1)
#print(maze)
ans=float('inf')
def dfs(x,y,step):
global ans
if step>=ans:#剪枝
return
if x==gx and y==gy:
if step<ans:
ans=step
return
for dx,dy in [(1,0),(-1,0),(0,-1),(0,1)]:
nx=dx+x
ny=dy+y
if 0<=nx<n and 0<=ny<m and vis[nx][ny]!=1 and maze[nx][ny]!='#':
vis[x][y]=1
dfs(nx,ny,step+1)#必须走一步,故没有选与不选
vis[x][y]=0
return
dfs(sx,sy,0)
print(ans)