import java.util.*; public class Main { public static int[] dijstra(ArrayList e[], ArrayList c[], int start) { PriorityQueue dij = new PriorityQueue<>(); int ans[] = new int[e.length]; boolean ok[] = new boolean[e.length]; Arrays.fill(ans, Integer.MAX_VALUE); ans[start] = 0; ok[start] = true; dij.add(new Edge(start, 0)); while (!dij.isEmpty()) { Edge ed = dij.poll(); if (ans[ed.p] < ed.c) continue; int a = ed.p; ok[a] = true; for (int i = 0; i < e[a].size(); i++) { int x = e[a].get(i); int y = c[a].get(i); if (!ok[x] && ans[x] > ans[a] + y) { ans[x] = ans[a] + y; dij.add(new Edge(x, ans[x])); } } } return ans; } public static void main(String[] args) { Scanner sc=new Scanner (System.in); int n=sc.nextInt(); int hp=sc.nextInt(); int map[][]=new int[n][n]; int ox=sc.nextInt()-1; int oy=sc.nextInt()-1; for(int i=0;ie[]=new ArrayList[n*n]; ArrayList c[]=new ArrayList[n*n]; for(int i=0;i(); c[i]=new ArrayList<>(); } for(int i=0;i=n || ny<0 || ny>=n)continue; e[i].add(nx*n+ny); c[i].add(map[nx][ny]); } } int dij[]=dijstra(e,c,0); int g=(n-1)*(n-1); if(dij[g]dij[g]){ System.out.println("YES"); return; } } System.out.println("NO"); } } class Edge implements Comparable {//scacheさんから拝借 int p; int c; public Edge(int p, int c) { this.p = p; this.c = c; } public Edge() { } @Override public int compareTo(Edge o) { return this.c - o.c; } }