HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50818 - Depth Limited BST

Guest
• Review clarifications (1)

Volume problems

• 50712 - Moon algebra
• 50675 - Kruja Boys
• 50415 - The Scientist
• 50679 - Jetpack Hurdle Jumping
• 50717 - Hurdle Jumping
• 50421 - Repairing road segments
• 50431 - Sultan's Game
• 50429 - Secret Message
• 50818 - Depth Limited BST
• 50836 - Censored
• 50505 - kht Puzzle
• 50840 - Tanker trucks
• 50877 - Friendly Queue
• 50876 - He is my cousin
• 50997 - Dynamic Knights
• 50490 - Across the River
• 50816 - Largest Sum Path

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