Advertisement
Guest User

maxsum

a guest
Jun 5th, 2021
117
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.  
  17. long long solution(node* root){
  18.         // write your code here
  19. }
  20.  
  21.  
  22. signed main(){
  23.     int n,r; cin >> n >> r;
  24.     vector<node*>vec(n+1);
  25.     for(int i = 1; i <= n; i++){
  26.             int t; cin >> t;
  27.             vec[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.                 vec[i] -> left = vec[x];
  33.             }if(y != -1){
  34.                 vec[i] -> right = vec[y];
  35.             }
  36.     }
  37.     cout << solution(vec[r]) << endl;
  38. }
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement