char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h; f(x,y,r,s,t){ for(u[x][y]=a;r<4;){ s=x+d[r];t=y+d[++r]; if(s>=0&&t>=0&&s