Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct node{
- int key;
- int left;
- int right;
- };
- node a[300001];
- int it = 1;
- bool check(int ind, int c, int b)
- {
- if (ind == NULL)
- {
- return true;
- }
- if (a[ind].key < c || a[ind].key > b)
- {
- return false;
- }
- return check(a[ind].left, c, a[ind].key) && check(a[ind].right, a[ind].key, b);
- }
- int main()
- {
- // ifstream fin("check.in");
- //ofstream fout("check.out");
- int n, si = 0;
- cin >> n;
- if (n == 0)
- {
- cout << "YES";
- return 0;
- }
- for (int i = 1; i <= n; i++)
- {
- cin >> a[i].key >> a[i].left >> a[i].right;
- }
- if (check(1, LONG_MIN, LONG_MAX))
- cout << "YES";
- else
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement