using System; using System.Text; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int h = inpt[0]; int w = inpt[1]; inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int sY = inpt[0] - 1; int sX = inpt[1] - 1; int gY = inpt[2] - 1; int gX = inpt[3] - 1; int[,] map = new int[h, w]; bool[,] flags = new bool[h, w]; for(int i=0; i que = new Queue(); que.Enqueue(new int[]{sY, sX}); while(que.Count > 0) { int[] pos = que.Dequeue(); if(pos[0] == gY && pos[1] == gX) { continue; } List next = new List(); for(int i=pos[0]-1; i<=pos[0]+1; i++) { for(int j=pos[1]-1; j<=pos[1]+1; j++) { if(i==pos[0] && j==pos[1]) { continue; } if(i!=pos[0] && j!=pos[1]) { continue; } if(i<0||i>=h||j<0||j>=w) { continue; } if(Math.Abs(map[i,j] - map[pos[0], pos[1]]) <= 1) { next.Add(new int[]{i,j}); } } } for(int i=pos[0]-2; i<=pos[0]+2; i+=2) { for(int j=pos[1]-2; j<=pos[1]+2; j+=2) { if(i==pos[0] && j==pos[1]) { continue; } if(i!=pos[0] && j!=pos[1]) { continue; } if(i<0||i>=h||j<0||j>=w) { continue; } if(map[i,j] == map[pos[0], pos[1]]) { int tani = 0; if(i == pos[0]) { tani = map[i, (pos[1] + j)/2]; } else { tani = map[(i+pos[0])/2, j]; } if(tani < map[i,j]) { next.Add(new int[]{i,j}); } } } } foreach(int[] nextPos in next) { if(flags[nextPos[0], nextPos[1]]) { continue; } flags[nextPos[0], nextPos[1]] = true; que.Enqueue(nextPos); } } Console.WriteLine(flags[gY, gX]?"YES":"NO"); } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 10 12 4 1 1 12 879572576859 445569966665 033345689389 011246557476 000224557745 000022346548 000000425665 000002223544 000000003223 000000000243 "; public static string ReadLine() { if(IsDebug) { if(SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }