Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct Node{
- int key, l, r;
- };
- Node a[200001];
- bool check(Node root)
- {
- if ((root.key > a[root.r].key) && (root.r > 0))
- return false;
- if ((root.key < a[root.l].key) && (root.l > 0))
- return false;
- if (root.l > 0)
- check(a[root.l]);
- if (root.r > 0)
- check(a[root.r]);
- return true;
- }
- int le, ri;
- int main()
- {
- freopen("check.in", "r", stdin);
- freopen("check.out", "w", stdout);
- int n, key, l, r;
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i].key >> a[i].l >> a[i].r;
- if (check(a[1])== true)
- cout << "YES";
- else
- cout << "NO";
- return 0;
- }
- /*
- 6
- -2 0 2
- 8 4 3
- 9 0 0
- 3 5 6
- 0 0 0
- 6 0 0
- */
- /*
- 0
- */
- /*
- 3
- 5 2 3
- 6 0 0
- 4 0 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement