#include #include #include #include #include #include #include #include #include using namespace std; int h, w, sx, sy, gx, gy; int b[50][50]; bool visited[50][50]; typedef pair P; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; bool in(int x, int y) { return 0 <= x && x < w && 0 <= y && y < h; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> h >> w >> sy >> sx >> gy >> gx; sx--, sy--, gx--, gy--; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { char c; cin >> c; b[i][j] = c - '0'; } } queue

q; q.push(P(sx, sy)); visited[sy][sx] = true; while(q.size()) { int x = q.front().first, y = q.front().second; q.pop(); for(int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if(in(nx, ny) && !visited[ny][nx] && abs(b[ny][nx] - b[y][x]) <= 1) { visited[ny][nx] = true; q.push(P(nx, ny)); } int nnx = nx + dx[i], nny = ny + dy[i]; if(in(nnx, nny) && !visited[nny][nnx] && b[nny][nnx] == b[y][x] && b[y][x] > b[ny][nx]) { visited[nny][nnx] = true; q.push(P(nnx, nny)); } } } if(visited[gy][gx]) { cout << "YES" << endl; } else { cout << "NO" << endl; } }