提交记录
#include<stdio.h>
#include<queue>
using namespace std;
const int N =105;
char a[N][N][N];
bool b[N][N][N];
const int nx[6]={1,-1,0,0,0,0};
const int ny[6]={0,0,1,-1,0,0};
const int nz[6]={0,0,0,0,1,-1};
struct node {
int x,y,z,stp;
};
queue<node> Q;
int m,n,k,ex,ey,ez;
int main() {
ZSB:scanf("%d%d%d",&m,&n,&k);
while(!Q.empty()) Q.pop();
if(m==0) return 0;
for(int i=0;i<m;i++) {
for(int j=0;j<n;j++) {
scanf("%s",a[i][j]);
for(int h=0;h<k;h++) {
if(a[i][j][h]=='S') {
Q.push({i,j,h,0});
}
if(a[i][j][h]=='E') {
ex=i;ey=j;ez=h;
}
}
}
}
while(!Q.empty()) {
int x=Q.front().x , y=Q.front().y , z=Q.front().z , stp=Q.front().stp;Q.pop();
if(x==ex&&y==ey&&z==ez) {
printf("Escaped in %d minute(s).\n",stp);
goto ZSB;
}
b[x][y][z]=true;
for(int pos=0;pos<6;pos++) {
int tx=x+nx[pos] , ty=y+ny[pos] , tz=z+nz[pos];
if(tx<0||ty<0||tz<0||tx>=m||ty>=n||tz>=k||b[tx][ty][tz]||a[tx][ty][tz]=='#') continue;
Q.push({tx,ty,tz,stp+1});
}
}
puts("Trapped!");
goto ZSB;
}