-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1155.cpp
More file actions
32 lines (29 loc) · 811 Bytes
/
1155.cpp
File metadata and controls
32 lines (29 loc) · 811 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
vector<int> tree, path;
bool is_max_heap = true, is_min_heap = true;
void dfs(int id) {
path.push_back(tree[id]);
if (2 * id + 1 >= tree.size()) {
for (int i = 0; i < path.size() - 1; i++) {
if (path[i] < path[i+1]) is_max_heap = false;
if (path[i] > path[i+1]) is_min_heap = false;
cout << path[i] << " ";
}
cout << path.back() << endl;
} else {
if (2 * id + 2 < tree.size()) dfs(2 * id + 2);
dfs(2 * id + 1);
}
path.pop_back();
}
int main() {
int n;
cin >> n;
tree.resize(n);
for (int i = 0; i < n; i++) cin >> tree[i];
dfs(0);
cout << (is_max_heap ? "Max Heap" : is_min_heap ? "Min Heap" : "Not Heap") << endl;
return 0;
}