#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996) #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>=(b);i--) #define pb push_back #define mp(a,b) make_pair(a,b) #define all(a) a.begin(),a.end() #define len(x) ((int)(x).size()) #define tmax(a,b,c) max((a),max((b),(c))) #define tmin(a,b,c) min((a),min((b),(c))) #define debug(x) cerr << #x << " is " << x << endl; #define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define debuga(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;} #define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl; typedef pair Pii; typedef map Mii; typedef vector Vi; typedef vector > VVi; typedef long long ll; const int inf = 2e9; const ll ll_inf = 1e17; const int mod = 1e9 + 7; const long double eps = 1e-10; typedef pair Pll; int h, w; int sx, sy, gx, gy; int g[51][51]; int dx[4] = {0,1,0,-1}; // nesw int dy[4] = {1,0,-1,0}; int used[51][51]; int main() { cin >> h >> w; cin >> sy >> sx >> gy >> gx; sx--; sy--; gx--; gy--; rep(i,0,h) rep(j,0,w) { char c; cin >> c; g[i][j] = (int)(c - '0'); } //debuga(g,h,w); queue que; que.push(mp(sy,sx)); used[sy][sx] = true; while (!que.empty()) { Pii p = que.front(); que.pop(); int by = p.first, bx = p.second; if (bx == gx && by == gy) { cout << "YES" << endl; return 0; } int height = g[by][bx]; //printf("height=%d by=%d bx=%d\n",height,by,bx); rep(i,0,4) { int nx = bx + dx[i]; int ny = by + dy[i]; if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue; if (used[ny][nx]) continue; int t = g[ny][nx]; if (height-1 <= t && t <= height+1) { que.push(mp(ny,nx)); used[ny][nx] = true; } } rep(i,0,4) { int nx = bx + dx[i] + dx[i]; int ny = by + dy[i] + dy[i]; if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue; if (used[ny][nx]) continue; int t = g[ny][nx]; if (t == height && g[by+dy[i]][bx+dx[i]] < t) { que.push(mp(ny,nx)); used[ny][nx] = true; } } } cout << "NO" << endl; return 0; }