Advertisement
Guest User

maxdepth

a guest
Jun 4th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 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. int solution(node* root){
  17.             // write your code here
  18. }
  19.  
  20.  
  21. int main(){
  22.         int n; cin >> n;
  23.         vector<node*> vec(n+1);
  24.         int root; cin >> root;
  25.         for(int i = 1; i <= n; i++){
  26.             vec[i] = new node(i);
  27.         }
  28.         for(int i = 1; i <= n; i++){
  29.             int x,y; cin >> x >> y;
  30.             if(x != -1){
  31.                 vec[i] -> left = vec[x];
  32.             }if(y != -1){
  33.                 vec[i] -> right = vec[y];
  34.             }
  35.         }
  36.         cout << solution(vec[root]) << endl;
  37. }
  38.  
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement