Description
INPUT
OUTPUT
SAMPLE INPUT
SAMPLE OUTPUT
HINT
#include<iostream>
#include<queue>
using namespace std;
struct node
{
int x,y,z,step;
};
char map[11][11][11],a[10];
int n,bx,by,bz,ex,ey,ez,dir[6][3]={{0,0,1},{0,1,0},{1,0,0},{0,0,-1},{0,-1,0},{-1,0,0}};
void bfs()
{
int flag=0,ans,i;
node p1;
p1.x=bx;
p1.y=by;
p1.z=bz;
p1.step=0;
queue<node>Q;
Q.push(p1);
map[bx][by][bz]='X';
map[ex][ey][ez]='O';
while(!Q.empty())
{
p1=Q.front();
Q.pop();
if(p1.x==ex&&p1.y==ey&&p1.z==ez)
{
flag=1;
ans=p1.step;
break;
}
for(i=0;i<6;i++)
{
node p2;
p2.x=p1.x+dir[i][0];
p2.y=p1.y+dir[i][1];
p2.z=p1.z+dir[i][2];
if(map[p2.x][p2.y][p2.z]!='X'&&p2.x>=0&&p2.x<n&&p2.y>=0&&p2.y<n&&p2.z>=0&&p2.z<n)
{
map[p2.x][p2.y][p2.z]='X';
p2.step=p1.step+1;
Q.push(p2);
}
}
}
if(flag)
cout<<n<<" "<<ans<<endl;
else
cout<<"NO ROUTE"<<endl;
}
int main()
{
int i,j,k;
while(cin>>a>>n)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
cin>>map[i][j][k];
cin>>bx>>by>>bz>>ex>>ey>>ez;
cin>>a;
bfs();
}
}