#include #define endl '\n' #define TRACE(x) cerr << #x << " = " << x << endl using namespace std; template inline bool chkmax(T &x, const T1 &y) { return x < y ? x = y, true : false; } template inline bool chkmin(T &x, const T1 &y) { return x > y ? x = y, true : false; } const bool ONPC = false; const int MAXN = 1001; int n, k; int x1, y1; int x2, y2; int board[MAXN][MAXN]; void read() { if (!ONPC) { freopen("chess.in", "rt", stdin); freopen("chess.out", "wt", stdout); } cin >> n >> k >> x1 >> y1 >> x2 >> y2; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cin >> board[i][j]; } } int dr[8] = {1, 1, 2, 2, -1, -1, -2, -2}; int dc[8] = {2, -2, 1, -1, 2, -2, 1, -1}; bool isOut(int x, int y) { return x <= 0 || x > n || y <= 0 || y > n; } int turns[MAXN][MAXN]; void bfs() { queue> q; q.push({x1, y1}); memset(turns, -1, sizeof(turns)); turns[x1][y1] = 0; while (!q.empty()) { pair curr = q.front(); q.pop(); for (int i = 0; i < 8; i++) { int nx = curr.first + dr[i]; int ny = curr.second + dc[i]; if (!isOut(nx, ny) && !board[nx][ny] && turns[nx][ny] == -1) { turns[nx][ny] = turns[curr.first][curr.second] + 1; q.push({nx, ny}); } } } } void solve() { bfs(); cout << (turns[x2][y2] <= k ? "Yes\n" : "No\n"); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); solve(); return EXIT_SUCCESS; }