Construct the Binary Tree

CodeForces - 1311E