#include #include using namespace std; string b[52]; bool is_search[52][52]; int xvec[4] = {-1, 0, 1, 0}, yvec[4] = {0, -1, 0, 1}; int xvec2[4] = {-2, 0, 2, 0}, yvec2[4] = {0, -2, 0, 2}; int h, w; void dfs(int y, int x) { //cout << "now is " << x << " " << y << endl; is_search[y][x] = true; char nows = b[y][x]; int nowtmp = (int)nows - '0'; for (int i = 0; i < 4; i++) { if (x + xvec[i] < 0 || x + xvec[i] > w-1 || y + yvec[i] < 0 || y + yvec[i] > h-1) continue; char stmp = b[y + yvec[i]][x + xvec[i]]; int tmp = (int)stmp - '0'; //cout << tmp << endl;; if(is_search[y + yvec[i]][x + xvec[i]] == false && (nowtmp == tmp + 1 || nowtmp == tmp - 1 || nowtmp == tmp)) { dfs(y + yvec[i], x + xvec[i]); } if (x + xvec2[i] < 0 || x + xvec2[i] > w-1 || y + yvec2[i] < 0 || y + yvec2[i] > h-1) continue; char sstmp = b[y + yvec2[i]][x + xvec2[i]]; int ttmp = (int)sstmp - '0'; //cout << ttmp << endl;; if(is_search[y + yvec2[i]][x + xvec2[i]] == false && nowtmp == ttmp) { if (ttmp > tmp) dfs(y + yvec2[i], x + xvec2[i]); } } } int main(void) { int sx, sy, gx, gy; cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { is_search[i][j] = false; } } cin >> sx >> sy >> gx >> gy; for (int i = 0; i < h; i++) { cin >> b[i]; } dfs(sx-1, sy-1); /*for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cout << is_search[i][j] << " "; } cout << endl; }*/ if(is_search[gx-1][gy-1]) cout << "YES" << endl; else cout << "NO" << endl; return 0; }