#include using namespace std; #include using namespace atcoder; using ll = long long; int n,v,ox,oy; vector> L; int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1}; using P = pair; void solve(){ vector> G(n*n); for(int i = 0;i=n||j+dy[k]<0||j+dy[k]>=n)continue; int ed = (i+dx[k])*n + (j+dy[k]); G[st].push_back(P(ed,L[i+dx[k]][j+dy[k]])); } } } auto dijkstra = [&](int st,int ed){ priority_queue,greater<>>PQ; vector dist(n*n,INT_MAX); PQ.push(P(0,st)); dist[st] = 0; while(PQ.size()){ auto [curCost,cur] = PQ.top(); PQ.pop(); if(curCost!=dist[cur])continue; for(auto &[to,toCost]:G[cur]){ if(dist[to]>curCost+toCost){ dist[to] = curCost+toCost; PQ.push(P(dist[to],to)); } } } return dist[ed]; }; bool is = false; if(dijkstra(0,n*n-1)dijkstra(ox*n+oy,n*n-1)){ is = true; } if(is)cout<<"YES"<> n >> v >> ox >> oy; L = vector>(n,vector(n)); for(int i = 0;i> L[i][j]; } ox--; oy--; solve(); }