#include // #include using namespace std; // using namespace atcoder; using ll = long long; using ld = long double; using P = pair; using vl = vector; const int INF = 1e9; const ll LINF = 1e18; const double eps = 1e-10; #define fi first #define se second #define eb emplace_back #define rep(i,n) for(ll i = 0; i < (ll)(n); ++i) #define srep(i, s, n) for (ll i = s; i < (ll)(n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define fore(i,x) for(auto &i:x) #define ALL(x) x.begin(),x.end() #define RALL(x) x.rbegin(),x.rend() #define sz(x) (ll)x.size() #define dame { puts("-1"); return;} #define yes { puts("Yes"); return;} #define no { puts("No"); return;} #define ret(x) { cout<<(x)<<'\n'; return;} bool is_pop(ll hash, ll d){return (hash>>d)&1;} template using vc = vector; template using vv = vc>; template using PQ = priority_queue,greater>; templatevoid in(T&... a) { (cin >> ... >> a); } void out() { cout << '\n'; } templatevoid out(const T& a, const Ts&... b) { cout << a;(cout << ... << (cout << ' ', b));cout << '\n'; } template< typename T >istream &operator>>(istream &is, vector< T > &v){for(T &in : v) is >> in;return is;} template< typename T >ostream &operator<<(ostream &os, const vector< T > &v){for(int i = 0; i < (int) v.size(); i++) {os << v[i] << (i + 1 != (int) v.size() ? " " : "");}return os;} templateconstexpr auto min(T... a) { return min(initializer_list>{a...}); } templateconstexpr auto max(T... a) { return max(initializer_list>{a...}); } templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b a(h,vl(w)); in(a); ll now = a[x][y]; PQ> q; vv used(h,vc(w)); used[x][y] = true; rep(i,4) { ll nx = x + di[i], ny = y + dj[i]; if(nx<0||nx>=h||ny<0||ny>=w) continue; used[nx][ny] = true; q.emplace(a[nx][ny],nx,ny); } while(sz(q)) { auto [po,sx,sy] = q.top(); if(po >= now) break; q.pop(); now += po; x = sx; y = sy; rep(i,4) { ll nx = x + di[i], ny = y + dj[i]; if(nx<0||nx>=h||ny<0||ny>=w) continue; if(used[nx][ny]) continue; used[nx][ny] = true; q.emplace(a[nx][ny],nx,ny); } } if(sz(q)) no else yes }