1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<vector> 5 #include<queue> 6 #include<cstring> 7 using namespace std; 8 struct node 9 { 10 int x; 11 int y; 12 int z; 13 int step; 14 }; 15 char dung[35][35][35]; 16 int d[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}}; 17 int l, r, c; 18 int main() 19 { 20 // freopen("in.in","r",stdin); 21 char tp[40]; 22 node start, tmp; 23 int ans = 0; 24 queue<node>q; 25 while(cin>>l>>r>>c) 26 { 27 ans = 0; 28 memset(dung,0,sizeof(dung)); 29 if(l*r*c == 0) break; 30 for(int k = 1; k <= l; k++) 31 for(int i = 1; i <= r; i++) 32 { 33 cin>>tp; 34 for(int j = 1; j <= c; j++) 35 { 36 dung[k][i][j] = tp[j-1]; 37 if(tp[j-1]=='S') 38 { 39 start.x = i; 40 start.y = j; 41 start.z = k; 42 start.step = 0; 43 } 44 } 45 } 46 q.push(start); 47 dung[start.z][start.x][start.y] = '#'; 48 while(q.size()) 49 { 50 start = q.front(); 51 q.pop(); 52 for(int i = 0; i < 6; i++) 53 { 54 tmp.x = start.x + d[i][0]; 55 tmp.y = start.y + d[i][1]; 56 tmp.z = start.z + d[i][2]; 57 tmp.step = start.step + 1; 58 if(dung[tmp.z][tmp.x][tmp.y] == 'E') 59 { 60 ans = tmp.step; 61 break; 62 } 63 if(dung[tmp.z][tmp.x][tmp.y]!='.') continue; 64 q.push(tmp); 65 dung[tmp.z][tmp.x][tmp.y] = '#'; 66 } 67 } 68 if(ans) printf("Escaped in %d minute(s). ",ans); 69 else printf("Trapped! "); 70 while(q.size()) q.pop(); 71 } 72 return 0; 73 }