#include #include #include using namespace std; const int DX[4] = {1, 0, -1, 0}; const int DY[4] = {0, 1, 0, -1}; const int INF = 1000000; int N, V, OX, OY; int L[202][202]; int dist[202][202]; void bfs(int sx, int sy) { for (int i = 0; i < N + 2; i++) { for (int j = 0; j < N + 2; j++) { dist[i][j] = V + 1; } } priority_queue > P; P.push(make_pair(0, sx + sy * (N + 2))); dist[sx][sy] = 0; while (!P.empty()) { pair p = P.top(); P.pop(); int x = p.second % (N + 2), y = p.second / (N + 2); if (-p.first > dist[x][y]) { continue; } for (int d = 0; d < 4; d++) { int xx = x + DX[d], yy = y + DY[d]; if (dist[x][y] + L[xx][yy] < dist[xx][yy]) { dist[xx][yy] = dist[x][y] + L[xx][yy]; P.push(make_pair(-dist[xx][yy], xx + yy * (N + 2))); } } } } int main() { cin >> N >> V >> OX >> OY; for (int i = 0; i < N + 2; i++) { for (int j = 0; j < N + 2; j++) { L[i][j] = INF; } } for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { cin >> L[x + 1][y + 1]; } } bfs(1, 1); if (dist[N][N] <= V) { cout << "YES" << endl; } else if (dist[OX][OY] <= V) { V -= dist[OX][OY]; V *= 2; bfs(OX, OY); if (dist[N][N] <= V) { cout << "YES" << endl; } else { cout << "NO" << endl; } } else { cout << "NO" << endl; } return 0; }