#include<bits/stdc++.h>
using namespace std;

const int N = 1e2+10;

int mp[N][N],vis[N][N]; 

bool fg = false;

int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int n;

int sx,sy,ex,ey;


void dfs(int x,int y) {
	if(fg) return;
	if(x == ex && y == ey) {
		fg = true;
		return;
	}
	for(int i = 0;i < 4; ++i) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx > 0 && nx <= n && ny > 0 && ny <= n && vis[nx][ny] == false && mp[nx][ny] == 0){
            vis[nx][ny] = true;
			dfs(nx,ny);
            vis[nx][ny] = false;
		}
	}
}


int main()
{
	
	cin>>n;
	for(int i = 1;i <= n; ++i) {
		for(int j = 1;j <= n; ++j) {
			cin>>mp[i][j];
		}
	}
	cin>>sx>>sy>>ex>>ey;
	if(mp[sx][sy] == 1) {
		puts("NO");
		return 0;
	}
	dfs(sx,sy);
	puts(fg?"YES":"NO");
	
	
	
	return 0;
}

0 comments

No comments so far...