#include #include #include template struct DisjointSet { DisjointSet() { for(int i = 0; i < (int)size; ++i) parent[i] = i; } int parent[size]; }; template int find(DisjointSet& ds, int x) { if( ds.parent[x] == x ) return x; return ds.parent[x] = find(ds, ds.parent[x]); } template void unite(DisjointSet& ds, int x, int y) { x = find(ds, x); y = find(ds, y); if( x == y ) return; std::random_device rd; if( rd() & 1 ) std::swap(x, y); ds.parent[x] = y; } template bool same(DisjointSet& ds, int x, int y) { return find(ds, x) == find(ds, y); } int coord(int r, int c) { return r * 64 + c; } int main() { DisjointSet<64*64> ds; int h, w; scanf("%d %d", &h, &w); int sx, sy, gx, gy; scanf("%d %d %d %d", &sx, &sy, &gx, &gy); sx -= 1; sy -= 1; gx -= 1; gy -= 1; int field[64][64]; for(int r = 0; r < h; ++r) { char buf[64]; scanf("%s", buf); for(int c = 0; c < w; ++c) { field[r][c] = buf[c] - '0'; } } int dr[4] = {1, 0, -1, 0}; int dc[4] = {0, 1, 0, -1}; for(int r = 0; r < h; ++r) { for(int c = 0; c < w; ++c) { for(int k = 0; k < 4; ++k) { int nr = r + dr[k]; int nc = c + dc[k]; if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue; if( std::abs(field[r][c] - field[nr][nc]) <= 1 ) { unite(ds, coord(r, c), coord(nr, nc)); } if( not ( field[r][c] > field[nr][nc] ) ) continue; int nr2 = nr + dr[k]; int nc2 = nc + dc[k]; if( not ( 0 <= nr2 and nr2 < h and 0 <= nc2 and nc2 < w ) ) continue; if( not ( field[r][c] == field[nr2][nc2] ) ) continue; unite(ds, coord(r, c), coord(nr2, nc2)); } } } puts( same(ds, coord(sx, sy), coord(gx, gy)) ? "YES" : "NO" ); return 0; }