Guest User

Untitled

a guest
Jun 5th, 2021
47
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  17.  
  18.  
  19. int solution(node* root){
  20.         // write your code here    
  21. }
  22.  
  23.  
  24. int main(){
  25.     int n,r; cin >> n >> r;
  26.     assert(n > 1);
  27.     vector<node*>vec(n+1);
  28.     for(int i = 1; i <= n; i++){
  29.             int t; cin >> t;
  30.             vec[i] = new node(t);
  31.     }
  32.     for(int i = 1; i <= n; i++){
  33.             int x,y; cin >> x >> y;
  34.             if(x != -1){
  35.                 vec[i] -> left = vec[x];
  36.             }if(y != -1){
  37.                 vec[i] -> right = vec[y];
  38.             }
  39.     }
  40.     cout << solution(vec[r]) << endl;
  41. }
  42.  
  43.  
  44.  
RAW Paste Data