#include #include #include #include #include #define N 300 using namespace std; typedef struct node { int x,y; int time; friend bool operator<(node n1,node n2) { return n2.time=m||y<0||y>=n||map[y][x]==-1) return 1; return 0; } int bfs() { priority_queueQ; while(!Q.empty()) Q.pop(); node fir,nex; fir.x=x1; fir.y=y1; fir.time=0; map[y1][x1]=-1; Q.push(fir); while(!Q.empty()) { fir=Q.top(); Q.pop(); if(fir.x==x2&&fir.y==y2) { return fir.time; } for(int i=0;i<4;i++) { nex.x=fir.x+dir[i][0]; nex.y=fir.y+dir[i][1]; if(judge(nex.x,nex.y)) continue; nex.time=fir.time+map[nex.y][nex.x]+1; map[nex.y][nex.x]=-1; Q.push(nex); } } return -1; } int main() { char c[N][N]; while(~scanf("%d%d",&n,&m)) { for(int i=0;i