Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- // You should only implement the function given below
- class node{
- public:
- int val;
- node* left;
- node* right;
- node(int val):val(val),left(nullptr),right(nullptr){}
- };
- bool solution(node* a, node* b){
- // write your code here
- }
- int main(){
- int n; cin >> n;
- int root1,root2; cin >> root1;
- vector<node*> a(n+1),b(n+1);
- for(int i = 1; i <= n; i++){
- int t;cin >> t;
- a[i] = new node(t);
- }
- for(int i = 1; i <= n; i++){
- int x,y; cin >> x >> y;
- if(x != -1){
- a[i]->left = a[x];
- }if(y != -1){
- a[i]->right = a[y];
- }
- }
- cin >> root2;
- for(int i = 1; i <= n; i++){
- int t;cin >> t;
- b[i] = new node(t);
- }
- for(int i = 1; i <= n; i++){
- int x,y; cin >> x >> y;
- if(x != -1){
- b[i]->left = b[x];
- }if(y != -1){
- b[i]->right = b[y];
- }
- }
- cout << (solution(a[root1],b[root2])?"YES":"NO") << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement