# Node class definitionclass Node: def __init__(self, val=None, left=None, right=None): self.val = val self.left = left self.right = right# function to construct binary tree from parent arraydef construct_tree(arr): # create dictionary to store child nodes for each parent node nodes = {} for i, parent in enumerate(arr): if parent not in nodes: nodes[parent] = [] nodes[parent].append(i) # create root node root = Node(0) # traverse tree in level order and create nodes queue = [root] while queue: node = queue.pop(0) if node.val in nodes: children = nodes[node.val] if children: node.left = Node(children[0]) queue.append(node.left) if len(children) > 1: node.right = Node(children[1]) queue.append(node.right) return root# example usageparent_arr = [-1, 0, 0, 1, 1, 3, 5]root = construct_tree(parent_arr)print(root.val) # output: 0print(root.left.val, root.right.val) # output: 1 Noneprint(root.left.left.val, root.left.right.val) # output: 3 4print(root.left.right.left.val, root.left.right.right.val) # output: 5 None