Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. struct tree{
  7. int m;
  8. int LeftChild;
  9. int RightChild;
  10. };
  11.  
  12. bool TreeorNot(vector<tree> &array, int node) {
  13. if (node < 0) {
  14. return true;
  15. } else {
  16. if ((node <= array[node].LeftChild) || (node >= array[node].RightChild)) {
  17. return false;
  18. } else {
  19. return (array, array[node].LeftChild)&&(array, array[node].RightChild);
  20. }
  21.  
  22. }
  23.  
  24. }
  25.  
  26.  
  27.  
  28. int main() {
  29. ifstream cin("check.in");
  30. ofstream cout("check.out");
  31. int n;
  32. int node = 0;
  33. cin >> n;
  34. vector<tree> array(n);
  35. if (n == 0) {
  36. cout << "YES";
  37. } else {
  38. for (int i = 0; i < n; ++i) {
  39. cin >> array[i].m >> array[i].LeftChild >> array[i].RightChild;
  40. --array[i].LeftChild;
  41. --array[i].RightChild;
  42. }
  43. }
  44. if (TreeorNot(array, node)){
  45. cout << "YES";
  46. } else {
  47. cout << "NO";
  48. }
  49. cin.close();
  50. cout.close();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement