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){}
- };
- int solution(node* root){
- // write your code here
- }
- int main(){
- int n,r; cin >> n >> r;
- assert(n > 1);
- vector<node*>vec(n+1);
- for(int i = 1; i <= n; i++){
- int t; cin >> t;
- vec[i] = new node(t);
- }
- for(int i = 1; i <= n; i++){
- int x,y; cin >> x >> y;
- if(x != -1){
- vec[i] -> left = vec[x];
- }if(y != -1){
- vec[i] -> right = vec[y];
- }
- }
- cout << solution(vec[r]) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement