Guest User

Untitled

a guest
Dec 8th, 2019
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Node
  7. {
  8. int key;
  9. int left;
  10. int right;
  11. };
  12.  
  13. void traversal(Node* arr, vector <int> &values, int i)
  14. {
  15. if (arr[i].left > 0)
  16. {
  17. traversal(arr, values, arr[i].left);
  18. }
  19. values.push_back(arr[i].key);
  20. if (arr[i].right > 0)
  21. {
  22. traversal(arr, values, arr[i].right);
  23. }
  24. return;
  25. }
  26.  
  27. int main()
  28. {
  29. ios_base::sync_with_stdio(false);
  30. freopen("height.in", "r", stdin);
  31. freopen("height.out", "w", stdout);
  32. int n, k, l, r;
  33. cin >> n;
  34. vector <int> values;
  35. Node arr[20];
  36. for (int i = 0; i < n; i++)
  37. {
  38. cin >> k >> l >> r;
  39. l--;
  40. r--;
  41. arr[i].key = k;
  42. arr[i].left = l;
  43. arr[i].right = r;
  44. }
  45. traversal(arr, values, 0);
  46. for (int i = 1; i < n; i++)
  47. {
  48. if (values[i - 1] >= values[i])
  49. {
  50. cout << "NO";
  51. return 0;
  52. }
  53. }
  54. cout << "YES";
  55. return 0;
  56. }
RAW Paste Data