#K91177. Minimal BST Correction
Minimal BST Correction
Minimal BST Correction
You are given a list of nodes representing a binary tree. Each node is given as three integers: value, left, and right. The value indicates the node's value, while left and right represent the value of the left and right children respectively. A child value of -1
indicates that there is no such child.
Your task is to construct the binary tree from the given list and check whether it is a valid Binary Search Tree (BST). Recall that in a BST, for every node with value \(v\), all nodes in its left subtree must have values strictly less than \(v\) and all nodes in its right subtree must have values strictly greater than \(v\). If the tree is a valid BST, output VALID
. Otherwise, output Needs further implementation for minimal correction calculation.
, as computing the minimal corrections is non-trivial and is not required for this problem.
Input/Output Requirements: The input is provided via stdin
and the output must be written to stdout
.
inputFormat
The first line contains an integer \(N\) — the number of nodes in the tree. The following \(N\) lines each contain three space-separated integers: value, left, and right. The first node in the list is the root of the tree.
outputFormat
If the constructed tree is a valid BST, output VALID
. Otherwise, output Needs further implementation for minimal correction calculation.
3
10 5 15
5 -1 -1
15 -1 -1
VALID