地牢大师
from collections import deque
不用deque 就TLE
from collections import deque
N = 110
l, r, c = 1, 1, 1
dx = [0, 0, 0, 0, 1, -1]
dy = [-1, 1, 0, 0, 0, 0]
dz = [0, 0, 1, -1, 0, 0]
def dfs(start,end):
q = deque()
q.append(start)
dist = [[[-1] * N for i in range(N)] for j in range(N)]
dist[start[0]][start[1]][start[2]] = 0
while len(q):
t = q.popleft()
for i in range(6):
z = t[0] + dz[i]
y = t[1] + dy[i]
x = t[2] + dx[i]
if z < 0 or z >= l or y < 0 or y >= r or x < 0 or x >= c:
continue
if a[z][y][x] == '#':
continue
if dist[z][y][x] != -1:
continue
dist[z][y][x] = dist[t[0]][t[1]][t[2]] + 1
if end == [z, y, x]:
return dist[z][y][x]
q.append([z, y, x])
return -1
while True:
a = [[[0] * N for i in range(N)] for j in range(N)]
l, r, c = map(int, input().split())
if l == r == c == 0:
break
for i in range(l):
for j in range(r):
a[i][j] = list(map(str, input()))
emp = input()
for i in range(l):
for j in range(r):
for k in range(c):
if a[i][j][k] == 'S':
start = [i, j, k]
if a[i][j][k] == 'E':
end = [i, j, k]
ans = dfs(start, end)
if ans == -1:
print("Trapped!")
else:
print("Escaped in "+str(ans)+" minute(s).")