import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; public class Main_yukicoder20 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int v = sc.nextInt(); int ox = sc.nextInt() - 1; int oy = sc.nextInt() - 1; int[][] matrix = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { matrix[i][j] = sc.nextInt(); } } int[] dx = {1, -1, 0, 0}; int[] dy = {0, 0, 1, -1}; Dijkstra di = new Dijkstra(n * n); for (int i = 0; i < n * n; i++) { int y = i / n; int x = i % n; for (int j = 0; j < dx.length; j++) { int ny = y + dy[j]; int nx = x + dx[j]; if (ny >= 0 && ny < n && nx >= 0 && nx < n) { int vv = ny * n + nx; di.addEdge(vv, i, matrix[y][x]); } } } if (di.getShortestPath(0, n * n - 1) <= v) { System.out.println("YES"); } else { long tmp = di.getShortestPath(0, oy * n + ox); if (tmp <= v && di.getShortestPath(oy * n + ox, n * n - 1) <= (v - tmp) * 2) { System.out.println("YES"); } else { System.out.println("NO"); } } sc.close(); } private static class Dijkstra { long[] d; List[] edges; PriorityQueue pq; int n; int s; final long INF = Long.MAX_VALUE; @SuppressWarnings("unchecked") Dijkstra(int n) { this.n = n; edges = new List[n]; for (int ii = 0; ii < n; ii++) { edges[ii] = new ArrayList(); } s = - 1; } // i, j:0-indexed public void addEdge(int i, int j, int c) { edges[i].add(new Edge(i, j, c)); } public long getShortestPath(int i, int j) { if (s != i) { d = new long[n]; Arrays.fill(d, INF); d[i] = 0; pq = new PriorityQueue(); pq.add(new Vertex(i, d[i])); while (!pq.isEmpty()) { Vertex u = pq.poll(); if (d[u.me] < u.d) { continue; // skip old vertex } for (int ii = 0; ii < edges[u.me].size(); ii++) { Edge v = edges[u.me].get(ii); if (d[u.me] != INF && d[v.v] > d[u.me] + v.w) { d[v.v] = d[u.me] + v.w; pq.add(new Vertex(v.v, d[v.v])); } } } s = i; } return d[j]; } private static class Edge { // int u; // from int v; // to int w; // cost Edge(int u, int v, int w) { // this.u = u; this.v = v; this.w = w; } } private static class Vertex implements Comparable { int me; // me long d; // cost Vertex(int u, long w) { this.me = u; this.d = w; } @Override public int compareTo(Vertex o) { // return Long.compare(this.d, o.d); return this.d > o.d ? 1 : this.d < o.d ? -1 : 0; } } } }