using System.Collections.Generic; using System.Linq; using System; public class P { public int x { get; set; } public int y { get; set; } } public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var h = int.Parse(line[0]); var w = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var sx = int.Parse(line[0]) - 1; var sy = int.Parse(line[1]) - 1; var gx = int.Parse(line[2]) -1; var gy = int.Parse(line[3]) -1; var map = new int[h, w]; for (int i = 0; i < h; i++) { var s = Console.ReadLine().Trim(); for (int j = 0; j < w; j++) map[i, j] = int.Parse(s[j].ToString()); } var res = goDfs(map, sx, sy, gx, gy); Console.WriteLine(res ? "YES":"NO"); } public static bool goDfs (int[,] map , int sx, int sy, int gx, int gy) { var h = map.GetLength(0); var w = map.GetLength(1); var dx = new int[] { 0, 1, 0, -1 }; var dy = new int[] { 1, 0, -1, 0 }; var used = new bool[h, w]; var q = new Queue
(); q.Enqueue(new P { x = sx, y = sy }); used[sx, sy] = true; while (q.Count() > 0) { var a = q.Dequeue(); if (a.x == gx && a.y == gy) return true; used[a.x, a.y] = true; for (int i = 0; i < 4; i++) { var nx = a.x + dx[i]; var ny = a.y + dy[i]; var nx2 = a.x + 2 * dx[i]; var ny2 = a.y + 2 * dy[i]; var nxm = (a.x + nx2) / 2; var nym = (a.y + ny2) / 2; if (nx >= 0 && nx < h && ny >= 0 && ny < w && Math.Abs(map[nx, ny] - map[a.x, a.y] )<= 1 && !used[nx, ny]) q.Enqueue(new P { x = nx, y = ny }); if (nx2 >= 0 && nx2 < h && ny2 >= 0 && ny2 < w && map[nxm,nym]< map[a.x,a.y] && map[nxm,nym] < map[nx2,ny2] && !used[nx2,ny2] ) q.Enqueue(new P { x = nx2, y = ny2}); } } return false; } }