//include //------------------------------------------ #include<stdio.h> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <stack> #include <ctime> #include <queue> using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //math //------------------------------------------- template<class T> inline T sqr(T x) {return x*x;} //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); //clear memory #define CLR(a) memset((a), 0 ,sizeof(a)) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #define WHITE 0 #define BLACK 1 #define INFTY 1000000000 #define MAX 200000 int maze[500][500]; int v[500][500]; int h,w; int sx,sy,gx,gy; void dfs(int y, int x){ //mark as visited // cout << x << y << ":" << maze[y][x] << endl; v[y][x] = BLACK; //tobikoe if(x >= 2 && maze[y][x]==maze[y][x-2] &&maze[y][x-1]<maze[y][x] && v[y][x-2]==WHITE)dfs(y,x-2); if(x <= w-3 && maze[y][x]==maze[y][x+2] &&maze[y][x+1]<maze[y][x] && v[y][x+2]==WHITE)dfs(y,x+2); if(y >= 2 && maze[y][x]==maze[y-2][x] &&maze[y-1][x]<maze[y][x] && v[y-2][x]==WHITE)dfs(y-2,x); if(y <= h-3 && maze[y][x]==maze[y+2][x] &&maze[y+1][x]<maze[y][x] && v[y+2][x]==WHITE)dfs(y+2,x); //hasigo if(x >= 1 && abs(maze[y][x]-maze[y][x-1])<=1 && v[y][x-1]==WHITE)dfs(y,x-1); if(x <= w-2 && abs(maze[y][x]-maze[y][x+1])<=1 && v[y][x+1]==WHITE)dfs(y,x+1); if(y >= 1 && abs(maze[y][x]-maze[y-1][x])<=1 && v[y-1][x]==WHITE)dfs(y-1,x); if(y <= h-2 && abs(maze[y][x]-maze[y+1][x])<=1 && v[y+1][x]==WHITE)dfs(y+1,x); return ; } int main() { cin >> h >> w; cin >> sy >> sx >> gy >> gx; REP(i,h){ char str[256]; scanf("%s",str); REP(j,w){ maze[i][j] = str[j]-'0'; v[i][j] = WHITE; } } dfs(sy-1,sx-1); // REP(i,h){ // REP(j,w){ // if(i==sy-1 && j == sx-1) // cout << "S"; // else cout << maze[i][j]; // }cout<<endl; // } // cout << maze[sy-1][sx-1] << endl; // REP(i,h){ // REP(j,w){ // if(i==gy-1 && j == gx-1) // cout << "G" ; // else cout << v[i][j]; // }cout<<endl; // } // cout << endl << gx << gy << endl; if(v[gy-1][gx-1]==BLACK)cout << "YES" << endl; else cout << "NO" << endl; return 0; }