n = int(input().split()[0])
nums = list(input().split())
path = []
res = []
s = set()
def backtracking(i,nums,path):
if 2*i+1>n-1 and 2*i+2>n-1:#遍历到叶子结点
print(" ".join(path))
if path == sorted(path):
s.add(1)
elif path == sorted(path,reverse=True):
s.add(0)
else:
s.add(3)
return
if 2*i+2<=n-1:#右分支
path.append(nums[2*i+2])
i = 2*i+2
backtracking(i,nums,path)
path.pop()
i = (i-2)//2
if 2*i+1<=n-1:#左分支
path.append(nums[2*i+1])
i = 2*i+1
backtracking(i,nums,path)
path.pop()
i = (i-1)//2
backtracking(0,nums,[nums[0]])
if len(s)>1:
print('Not Heap')
elif 1 in s:
print('Min Heap')
elif 0 in s:
print('Max Heap')
elif 3 in s:
print('Not Heap')
python1155 Heap Paths
最新推荐文章于 2024-11-01 20:08:05 发布