-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb.cpp
59 lines (42 loc) · 988 Bytes
/
b.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
struct Node {
int key;
int left;
int right;
};
bool check(int low, int high, int ind, const vector<Node>& tree) {
if (low >= high) {
return false;
}
if (ind == -1) {
return true;
}
if (tree[ind].key < low || tree[ind].key > high) {
return false;
}
return check(low, tree[ind].key, tree[ind].left, tree) &&
check(tree[ind].key, high, tree[ind].right, tree);
}
int main() {
ifstream fin("check.in");
ofstream fout("check.out");
int n;
fin >> n;
if (n <= 1) {
fout << "YES\n";
return 0;
}
vector<Node> tree(n);
for (auto& edge : tree) {
int k, f, s;
fin >> k >> f >> s;
edge = {k, f - 1, s - 1};
}
check(-2'000'000'000, 2'000'000'000, 0, tree) ? fout << "YES\n" : fout << "NO\n";
fin.close();
fout.close();
return 0;
}