HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50818 - Depth Limited BST

Guest
• Review clarifications (1)

Volume problems

• 50712 - Moon algebra
• 50978 - Albanian Coders
• 50699 - Fighting Vampires
• 50679 - Jetpack Hurdle Jumping
• 50717 - Hurdle Jumping
• 50692 - How much money?
• 50431 - Sultan's Game
• 50429 - Secret Message
• 50818 - Depth Limited BST
• 50386 - Conformity
• 50790 - Fire Alarm
• 50710 - Permutations
• 50709 - k-ary Strings
• 50708 - Binary Strings
• 50694 - The Cheapest Flight
• 50996 - Checkers - the shortest path
• 50770 - Average Depth

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Polian Spatina.

Depth Limited BST

Assume that you need to place some numbers in to an initially empty BST. But if the depth grows too big, the BST becomes un-manageable. And, you want to make sure that no element will be inserted to the tree if depth goes deeper than the given value d.

Question:
Write a program that inserts the given numbers in the BST while preserving the given depth. Then, you will be given another number (num). Check if num is in the tree or not.

Input specification
You will be first given 2 numbers

  • The number of numbers (n) where 1 ≤ n ≤ 10,000
  • The depth limit (d) where 1 ≤ d ≤ 50
Then in the following n lines, you will be given n numbers where each number is between -3e4 and 3e4. Searching number (num) will be given on the last line.

Output specification
If the given number is in the tree, show its depth. If it's not in the tree, show -1.

Sample Input I
8 2
15
17
12
14
16
1
13
18
13
Sample Input II
8 3
15
17
12
14
16
1
13
18
13
Sample Output I  
-1
Sample Output II
3


Для отправки решений необходимо выполнить вход.

www.contester.ru