For this Question: Given a binary tree with n nodes (numbered from 1 to n) having weight wi and left and right children (li, ri), find whether the given tree is BST or not.The first line of the input contains an integer n, the number of nodes in the tree.
The second line of input contains n integers, the values of the nodes of the tree.
The third line of the input contains an integer, denoting the root node of the tree.
Next n lines contain two integers l, r denoting the left and right child of the tree. (The value is 0 if there is no left or right child)

Constraints
1 <= n <= 50000
0 <= l, r <= n (0 denotes no child)
1 <= w <= 1000000000Output "YES" if the given tree is BST, else output "NO"Sample Input
5
10 3 9 2 1 
4
3 0
0 0
2 0
5 1
0 0

Sample Output 
YES, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;

class Node
{
public:
    Node( int v )
    {
        data = v;
        left = NULL;
        right = NULL;
    }
 
    int data;
    Node* left;
    Node* right;
};

bool isBST(Node *tree, int min, int max){
    
    if(tree == NULL)
        return true;

    if(tree -> data < min || tree -> data > max)
        return false;
    return isBST(tree -> left, min, tree -> data - 1) && isBST(tree -> right, tree -> data + 1, max);
}

int main(){
    int n;
    cin >> n;
    Node* *tree;
    tree = new Node*[n]; 
    for(int i = 0; i < n; i++){
        int value;
        cin >> value;
        tree[i] = new Node(value);
    }

    int root;
    cin >> root;

    for(int i = 0; i < n; i++){
        int left,right;
        cin>>left;
        cin>>right;
        if(left != 0)
            tree[i] -> left = tree[left - 1];
        if(right != 0)
            tree[i] -> right = tree[right - 1];
    }


    if(isBST(tree[root - 1], INT_MIN, INT_MAX))
        cout<< "YES";
    else
        cout<<"NO";
         
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?