#include #include #include using namespace std; typedef long long ll; typedef pair pll; vector G[4000100]; //weight,vertex priority_queue,greater> que; ll d[4000100],INF = 100000000000000000; void add_edge(int from,int to,ll weight){ G[from].push_back({weight,to}); // if(to==13) cout << from << " " << to << " " << weight << endl; } void dijkstra(int s){ que.push({0,s}); while(que.size()){ pll p = que.top(); que.pop(); ll dis = p.first,pos = p.second; if(d[pos]!=INF) continue; d[pos] = dis; for(auto e:G[pos]){ if(d[e.second]==INF) que.push({dis + e.first,e.second}); } } } int a[1010][1010]; int dx[8] = {1,1,0,-1,-1,-1,0,1}; int dy[8] = {0,1,1,1,0,-1,-1,-1}; bool ch(int h,int w,int nx,int ny){ if(nx<0 || nx>=h || ny<0 || ny>=w || a[nx][ny]==-1) return false; return true; } int mp(int w,int nx,int ny){ return w*nx + ny; } int main(){ int i,j,k,h,w; cin >> h >> w; for(i=0;i> a[i][j]; } } for(i=0;i