#include using namespace std; typedef long long ll; #define fst first #define sec second int dist[1000][1000]; int lr[1000][1000],ud[1000][1000]; int main(){ int w,h,n; cin>>w>>h>>n; for(int i=0;i>m; vector> b; for(int j=0;j>num; b.push_back(make_pair(num/w,num%w));//y,x } for(int j=1;j<=m;j++){ if(b[j].fst==b[j-1].fst){//横方向の移動 int sml=min(b[j].sec,b[j-1].sec); int big=max(b[j].sec,b[j-1].sec); lr[b[j].fst][sml]++; lr[b[j].fst][big]--; } else{ int sml=min(b[j].fst,b[j-1].fst); int big=max(b[j].fst,b[j-1].fst); ud[sml][b[j].sec]++; ud[big][b[j].sec]--; } } } for(int i=0;i> pq; pq.push(make_tuple(-0,0,0)); while(!pq.empty()){ auto it=pq.top(); pq.pop(); int cost=-get<0>(it); int y=get<1>(it),x=get<2>(it); if(cost>dist[y][x]) continue; if(y==h-1&&x==w-1){ cout<0&&dist[y][x+1]>cost){ dist[y][x+1]=cost; pq.push(make_tuple(-cost,y,x+1)); } if(x>0&&lr[y][x-1]>0&&dist[y][x-1]>cost){ dist[y][x-1]=cost; pq.push(make_tuple(-cost,y,x-1)); } if(ud[y][x]>0&&dist[y+1][x]>cost){ dist[y+1][x]=cost; pq.push(make_tuple(-cost,y+1,x)); } if(y>0&&ud[y-1][x]>0&&dist[y-1][x]>cost){ dist[y-1][x]=cost; pq.push(make_tuple(-cost,y-1,x)); } } cout<<"Odekakedekinai.."<