# -*- coding: utf-8 -*- """ No.424 立体迷路 https://yukicoder.me/problems/no/424 """ import sys from sys import stdin from collections import deque input = stdin.readline def bfs(maze, sx, sy, gx, gy, h, w): explored = [[False] * w for _ in range(h)] # 各マスが探索済かどうかのフラグ Q = deque() Q.append((sx, sy)) while Q: cx, cy = Q.popleft() # 現在地の座標 ch = maze[cy][cx] # 現在のマスの高さ # 隣りの同じ高さのブロックに歩いて移動 または 隣りの±1の高さのブロックにはしごをかけて移動 dx = [0, 0, -1, 1] dy = [-1, 1, 0, 0] for i in range(len(dx)): nx = cx + dx[i] ny = cy + dy[i] if (0 <= nx < w) and (0 <= ny < h) and explored[ny][nx] is False: nh = maze[ny][nx] # 移動先のマスの高さ if ch-1 <= nh <= ch+1: if nx == gx and ny == gy: return 'YES' Q.append((nx, ny)) explored[ny][nx] = True # 2ブロック先の同じ高さのマスにはしごを渡して移動 dx = [0, 0, -2, 2] dy = [-2, 2, 0, 0] for i in range(len(dx)): nx = cx + dx[i] ny = cy + dy[i] if (0 <= nx < w) and (0 <= ny < h) and explored[ny][nx] is False: nh = maze[ny][nx] # 移動先のマスの高さ mh = maze[(ny+cy)//2][(nx+cx)//2] # 間にあるマスの高さ if nh == ch and mh <= ch: if nx == gx and ny == gy: return 'YES' Q.append((nx, ny)) explored[ny][nx] = True return 'NO' def main(args): h, w = map(int, input().split()) sy, sx, gy, gx = map(int, input().split()) # h方向がx、w方向がyなので注意 maze = [] for _ in range(h): maze.append([int(x) for x in list(input().strip())]) ans = bfs(maze, sx-1, sy-1, gx-1, gy-1, h, w) # 入力は1起算なので-1する print(ans) if __name__ == '__main__': main(sys.argv[1:])