1419 - BST Problem 2 (I)   

Description

 

In this problem, please implement a binary search tree (BST).
You have to implement the following methods:


(1) Insert x:
      Insert an integer x into the BST if x hasn’t in the BST yet.
(2) Depth x:
      Find the node x in the BST and print the depth of x.
      The depth of root is 0. If x isn't in the BST, print -1.

 

Input

For each subproblem:

(1) 1419: N <= 2000
(2) 1420: N <= 20000
(3) 1421: N <= 50000

N is the number of nodes in the tree.

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss