HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN303 2013-15 Questions > problem:


15MdE-40. 50805 - Sum of the weights in a BST

CEN303 2013-15 Questions

Start: Dec.15.2013 at 02:00:00 PM
Finish: Dec.15.2013 at 07:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 15HW-10. 50826 - Olive Containers
• 15HW-30. 50828 - Arranging Time ...
• 15HW-40. 50676 - Cinema Millennium
• 15HW-40. 50829 - Decode an Image
• 15HW-50. 50830 - Sorting BST Nodes
• 15HW-60. 50678 - The Jumping Rabbit
• 15MdE-10. 50802 - Comparing Exams
• 15MdE-20. 50803 - Sum of the dept...
• 15MdE-40. 50805 - Sum of the ...
• 15PrE-10. 50816 - Largest Sum Path
• 15PrE-20. 50817 - The Knight Move
• 15PrE-30. 50818 - Depth Limited BST
• 15PrE-40. 50819 - Linked Numbers
• 15PrE2-01. 50847 - The first m train...
• 15PrE2-06. 50837 - Sum is equal to K
• 15Rst-10. 50857 - Nine-Stones Game
• 2.15FE-03. 50996 - Checkers - the ...

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 Sidrit Reka.

Sum of the weights in a BST

Question: You will be given a series of numbers to be inserted into an initially empty Binary Search Tree (BST). Each of the numbers will also contain a certain weight. Calculate the sum of the weights of all nodes found below a given node.

Input specification
You will be first given a number (n) the number of nodes to be inserted in the BST where 1 <= n <= 10000. Then you will be given in n lines, a pair of integers (id, weight) where id represents the number of the node and weight represents its weight where id 1 <= id, weight <= 10000. Then in the end you will be given the id of the node for which you have to calculate the sum of the weights of all nodes found below it.

Output specification
Show one integer which represents the sum of the weights of all nodes found below the given node. In case the given node is not found in the BST, just print 0.

Sample Input I
6
4 3
7 6
3 7
2 2
6 4
3 4
4
Sample Output I
19

We want to find the sum of the weights below node nr. 4. Below node 4 we have 4 other nodes (3, 2, 7, 6). We take the weight of each of these nodes and we sum them (7 + 2 + 6 + 4 = 19).

Sample Input II
9
6 3
8 4
2 2
4 1
1 6
7 3
9 2
3 5
5 1
2
Sample Output II
13

We want to find the sum of the weights below node nr. 2. Below node 2 we have 4 other nodes (1, 4, 3 ,5). We take the weight of each of these nodes and we sum them (6 + 1 + 5 + 1 = 13).



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

www.contester.ru