#include#include#include#include#include
using namespacestd;const int N=35,K=5,M=N*N,INF=0x3f3f3f3f-100;intn,m,Q,f[N][N][K][K],dis[N][N],dp[N][N][K];int he,tl,xx[K]={-1,0,0,1},yy[K]={0,-1,1,0};intex,ey,sx,sy,Tx,Ty,ans,tmp;boolb[N][N],vis[N][N][K];structNode{intx,y,p,dis;
Node(int x=0,int y=0,int a=0,int d=0):x(x),y(y),p(a),dis(d) {}bool operator< (const Node &b) const{return dis>b.dis;}//>!!!
}q[M];
priority_queuequ;void bfs(int x1,int y1,int x2,inty2)
{
he=tl=0; inttx,ty;
q[++tl]=Node(x1,y1,0,0);
memset(dis,0x3f,sizeofdis);
dis[x1][y1]=0;while(he
{
Node k=q[++he];for(int i=0;i<=3;i++)
{
tx=k.x+xx[i]; ty=k.y+yy[i];if(!b[tx][ty])continue;if(dis[tx][ty]>INF)
{
dis[