-
Notifications
You must be signed in to change notification settings - Fork 0
/
1155.py
42 lines (42 loc) · 943 Bytes
/
1155.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
n = int(input())
heap = list(map(int,input().split()))
heap.insert(0,0)
path = []
def dfs(root):
global path
if root > n:
return
path.append(heap[root])
if 2*root > n:
for i in range(len(path)):
print("%d"%path[i],end='')
if i != len(path)-1:
print(' ',end='')
else:
print('')
path.pop()
return
dfs(2*root+1)
dfs(2*root)
path.pop()
def isMax():
for i in range(1,n//2+1):
if heap[i] < heap[2*i]:
return False
if 2*i+1 <= n and heap[i] < heap[2*i+1]:
return False
return True
def isMin():
for i in range(1,n//2+1):
if heap[i] > heap[2*i]:
return False
if 2*i+1 <=n and heap[i] > heap[2*i+1]:
return False
return True
dfs(1)
if isMax():
print("Max Heap")
elif isMin():
print("Min Heap")
else:
print("Not Heap")