#include #define REP(i,n,N) for(int i=(n);i<(int) N;i++) #define p(s) cout<<(s)<>h>>w>>sx>>sy>>gx>>gy; REP(i,0,h) cin>>field[i]; sy--;sx--;gy--;gx--; ok[sx][sy]=true; queue> q; q.push({sx,sy}); while(!q.empty()){ auto now=q.front();q.pop(); REP(i,0,4){ int nx=now.F+dx[i],ny=now.S+dy[i]; if(!ok[nx][ny]&&CK(nx,0,h)&&CK(ny,0,w)&&abs(field[now.F][now.S]-field[nx][ny])<=1){ ok[nx][ny]=true; q.push({nx,ny}); } ny+=dy[i];nx+=dx[i]; if(!ok[nx][ny]&&CK(nx,0,h)&&CK(ny,0,w)&&field[nx][ny]==field[now.F][now.S]){ ok[nx][ny]=true; q.push({nx,ny}); } } } p(ok[gx][gy]?"YES":"NO"); return 0; }