ACW 1096. 地牢大师
#include <bits/stdc++.h>
using namespace std;
const int N =150;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int l,r,c,d[N][N][N];
char g[N][N][N];
int dx[6]={1,-1,0,0,0,0};
int dy[6]={0,0,1,-1,0,0};
int dz[6]={0,0,0,0,1,-1};
void bfs(int x1,int y1,int z1){
queue<tuple<int,int,int>>q;
q.push({x1,y1,z1});
memset(d,-1,sizeof d);
d[x1][y1][z1]=0;
while(!q.empty()) {
auto t = q.front();
q.pop();
for (int i = 0; i <= 5; i++) {
int x = get<0>(t) + dx[i], y = get<1>(t) + dy[i], z = get<2>(t) + dz[i];
if (x >= 1 && x <= r && y >= 1 && y <= c && z >= 1 && z <= l && d[x][y][z] == -1 && g[x][y][z]=='.') {
q.push({x, y, z});
d[x][y][z] = d[get<0>(t)][get<1>(t)][get<2>(t)] + 1;
}
}
}
}
signed main(){
fast
while(cin>>l>>r>>c,l&&r&&c){
memset(g,0,sizeof g);
int cnt=1,x1,y1,x2,y2,z1,z2;
while(cnt){
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
char s;cin>>s;
if(s!='#')g[i][j][cnt]='.';
if(s=='S')x1=i,y1=j,z1=cnt;
if(s=='E')x2=i,y2=j,z2=cnt;
}
}
cnt++;
if(cnt==l+1)break;
}
bfs(x1,y1,z1);
int t=d[x2][y2][z2];
if(t==-1)cout<<"Trapped!"<<Endl;
else cout<<"Escaped in "<<t<<" minute(s)."<<endl;
}
return 0^0;
}