Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct node{
  6. int key;
  7. int left;
  8. int right;
  9. };
  10.  
  11. node a[300001];
  12. int it = 1;
  13.  
  14. bool check(int ind, int c, int b)
  15. {
  16. if (ind == NULL)
  17. {
  18. return true;
  19. }
  20. if (a[ind].key < c || a[ind].key > b)
  21. {
  22. return false;
  23. }
  24. return check(a[ind].left, c, a[ind].key) && check(a[ind].right, a[ind].key, b);
  25. }
  26.  
  27. int main()
  28. {
  29. // ifstream fin("check.in");
  30. //ofstream fout("check.out");
  31. int n, si = 0;
  32. cin >> n;
  33. if (n == 0)
  34. {
  35. cout << "YES";
  36. return 0;
  37. }
  38. for (int i = 1; i <= n; i++)
  39. {
  40. cin >> a[i].key >> a[i].left >> a[i].right;
  41. }
  42. if (check(1, LONG_MIN, LONG_MAX))
  43. cout << "YES";
  44. else
  45. cout << "NO";
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement