import copy
queue = []
def Bfs() :
global N, M, H, day,queue,l
p = 0
le = len(queue)
while len(queue) != 0 :
if p == le :
p = 0
day += 1
le = len(queue)
q = queue.pop(0)
p += 1
if q[0]+1 < H and l[q[0]+1][q[1]][q[2]] == 0 :
queue.append([q[0]+1, q[1], q[2]])
l[q[0]+1][q[1]][q[2]] = 1
if q[0]-1 >= 0 and l[q[0]-1][q[1]][q[2]] == 0 :
queue.append([q[0]-1, q[1], q[2]])
l[q[0]-1][q[1]][q[2]] = 1
if q[1]+1 < N and l[q[0]][q[1]+1][q[2]] == 0 :
queue.append([q[0], q[1]+1, q[2]])
l[q[0]][q[1]+1][q[2]] = 1
if q[1]-1 >= 0 and l[q[0]][q[1]-1][q[2]] == 0 :
queue.append([q[0], q[1]-1, q[2]])
l[q[0]][q[1]-1][q[2]] = 1
if q[2]+1 < M and l[q[0]][q[1]][q[2]+1] == 0 :
queue.append([q[0], q[1], q[2]+1])
l[q[0]][q[1]][q[2]+1] = 1
if q[2]-1 >= 0 and l[q[0]][q[1]][q[2]-1] == 0 :
queue.append([q[0], q[1], q[2]-1])
l[q[0]][q[1]][q[2]-1] = 1
l = []
tl= []
day = 0
M, N, H = map(int, input().split())
for j in range(H) :
for i in range(N) :
v = list(map(int, input().split()))
tl.append(v)
l.append(copy.deepcopy(tl))
tl.clear()
for y in range(H) :
for z in range(N) :
for x in range(M) :
if l[y][z][x] == 1 :
queue.append([y, z, x])
l[y][z][x] = 1
Bfs()
for y in range(H) :
for z in range(N) :
for x in range(M) :
if l[y][z][x] == 0 :
print(-1)
exit()
else :
print(day)
exit()top of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
rhakdnsrhakdns
rhakdnsrhakdns
댓글 0개
좋아요
댓글(0)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page


