#include #include #include #include #include using namespace std; typedef pair P; int h,w; int sx,sy,gx,gy; vector> b(55,vector(55,-1)); vector> used(55,vector(55,false)); const int dx[] = {1,0,-1,0}; const int dy[] = {0,1,0,-1}; const int dx2[] = {2,0,-2,0}; const int dy2[] = {0,2,0,-2}; bool bfs(){ queue

que; que.push(P(sx,sy)); used[sx][sy] = true; while(!que.empty()){ P cur = que.front();que.pop(); if(cur.first == gx && cur.second == gy){ return true; } for(int i=0;i < 4;i++){ int nx = cur.first + dx[i],ny = cur.second + dy[i]; int nx2 = cur.first + dx2[i],ny2 = cur.second + dy2[i]; if(nx > 0 && nx <= h && ny > 0 && ny <= w){ int height = b[nx][ny] - b[cur.first][cur.second]; int height2 = b[nx2][ny2] - b[cur.first][cur.second]; if(height == 0 || height == 1 || height == -1){ if(!used[nx][ny]) que.push(P(nx,ny)); used[nx][ny] = true; }else if(height <= -1 && height2 == 0){ if(!used[nx2][ny2]) que.push(P(nx2,ny2)); used[nx2][ny2] = true; } } } } return false; } int main(){ cin >> h >> w; cin >> sx >> sy >> gx >> gy; for(int i=1;i <= h;i++){ string s; cin >> s; for(int j=1;j <= w;j++){ b[i][j] = s[j-1] - '0'; } } if(bfs()) cout << "YES" << endl; else cout << "NO" << endl; return 0; }