#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) #define FOR(i,a,b) for(ll i = (a);i<(b);i++) #define REP(i,a) FOR(i,0,(a)) #define MP make_pair int h, w; int sx, sy, gx, gy; int hyo[51][51] = {}; int DIRX[4] = {1, -1, 0, 0}; int DIRY[4] = {0, 0, 1, -1}; int DIRX2[4] = {2, -2, 0, 0}; int DIRY2[4] = {0, 0, 2, -2}; bool check(int nowx, int nowy){ if(nowx < 0 || nowy < 0 || nowy >= h || nowx >= w) return true; return false; } bool solve(){ queue > que; que.push(MP(sx, sy)); bool used[51][51] = {}; while(que.size()){ pair data = que.front();que.pop(); int nowx = data.first; int nowy = data.second; if(used[nowx][nowy]) continue; used[nowx][nowy] = true; // cout << nowx << "," << nowy << endl; if(nowx == gx && nowy == gy){ return true; } for(int i = 0;i < 4;i++){ int tox = nowx + DIRX[i], toy = nowy + DIRY[i]; if(check(tox, toy)) continue; if(abs(hyo[nowx][nowy] - hyo[tox][toy]) > 1) continue; // if(nowx == sx && nowy == sy){ // cout << tox << "," << toy << "-" << hyo[nowx][nowy] << endl; // } que.push(MP(tox, toy)); } for(int i = 0;i < 4;i++){ int tox = nowx + DIRX2[i], toy = nowy + DIRY2[i]; int midx = nowx + DIRX[i], midy = nowy + DIRY[i]; if(check(tox, toy)) continue; if(hyo[nowx][nowy] != hyo[tox][toy]) continue; if(hyo[midx][midy] > hyo[tox][toy]) continue; que.push(MP(tox, toy)); } } return false; } int main() { cin >> h >> w; cin >> sy >> sx >> gy >> gx; sx--;gx--;sy--;gy--; string str; for(int i = 0;i < h;i++){ cin >> str; for(int j = 0;j < str.size();j++){ hyo[j][i] = str[j] - '0'; } } // cout << sx << "--" << sy << endl; // cout << hyo[1][3] << endl; // cout << "--------------" << endl; // for(int i = 0;i < h;i++){ // for(int j = 0;j < w;j++){ // cout << hyo[j][i]; // } // cout << endl; // } bool ans = solve(); if(ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; }