ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Структуры данных > задача:


50818 - Depth Limited BST

Гость
• Вопросы к жюри (1)

Задачи раздела

• 50830 - Sorting BST Nodes
• 50803 - Sum of the depths in BST
• 50805 - Sum of the weights in a BST
• 50818 - Depth Limited BST
• 50770 - Average Depth
• 50836 - Censored
• 50816 - Largest Sum Path
• 50772 - The Path of a Node
• 50863 - Total Access Cost of a BST
• 50771 - BST Level Sum
• 50773 - Balanced Sum Tree
• 50411 - Sum of the Leaves

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
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