Advertisement
Guest User

sametree

a guest
Jun 4th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. // You should only implement the function given below
  6.  
  7. class node{
  8. public:
  9.     int val;
  10.     node* left;
  11.     node* right;
  12.  
  13.     node(int val):val(val),left(nullptr),right(nullptr){}
  14. };
  15.  
  16. bool solution(node* a, node* b){
  17.     // write your code here
  18. }
  19.  
  20.  
  21. int main(){
  22.     int n; cin >> n;
  23.     int root1,root2; cin >> root1;
  24.     vector<node*> a(n+1),b(n+1);
  25.     for(int i = 1; i <= n; i++){
  26.         int t;cin >> t;
  27.         a[i] = new node(t);
  28.     }
  29.     for(int i = 1; i <= n; i++){
  30.         int x,y; cin >> x >> y;
  31.         if(x != -1){
  32.             a[i]->left = a[x];
  33.         }if(y != -1){
  34.             a[i]->right = a[y];
  35.         }
  36.     }
  37.     cin >> root2;
  38.     for(int i = 1; i <= n; i++){
  39.         int t;cin >> t;
  40.         b[i] = new node(t);
  41.     }
  42.     for(int i = 1; i <= n; i++){
  43.         int x,y; cin >> x >> y;
  44.         if(x != -1){
  45.             b[i]->left = b[x];
  46.         }if(y != -1){
  47.             b[i]->right = b[y];
  48.         }
  49.     }
  50.  
  51.     cout << (solution(a[root1],b[root2])?"YES":"NO") << endl;
  52. }
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement