HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50929 - Present from your uncles

Guest
• Review clarifications (2)

Volume problems

• 51015 - Student Scholarships
• 50828 - Arranging Time Table
• 50447 - Swimming Contest - 2
• 51072 - Castle on chessboard
• 51082 - Sum is equal to K - 1
• 50794 - Writing Files Into HDD
• 51020 - Number of nodes removed
• 51023 - Preparing Keyword Index
• 50929 - Present from your uncles
• 51075 - Shortest Path for Bishop
• 50863 - Total Access Cost of a BST
• 50979 - Minimum access cost for BST
• 50688 - Epoka Furgon
• 50750 - Service Time - 2
• 50706 - The most crowded Club
• 50689 - The biggest building block
• 50686 - The Container

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 Ibrahim Mesecan.

Present from your uncles

Familia Hamzallari has a tradition. When a young family member graduates from university, just for once in his life, all other relatives and family members collect money for him to build his own business.

Question: You are given the list of people with the amount of money that they can give. Then, you will be given the relationship list. Find the total amount that Andi can take from all his relatives.

Input specification
You will be first given an integer (n) the number of people. Then, in the following n lines, you will be given the amount (integer) that each person can lend (between 0 and 2000). The first number is the amount that the person 1 can give, etc.

The next line contains two numbers the number of relationships given (m) and the ID of person who will take the money from his relatives (k). Then, in the following m lines you will be given two numbers: the relationship chart where people have the IDs from 1 to n where n, m and k are between 1 and 3000.

Output specification:
Show just one integer number, the total amount that Andi can take from all his relatives.

Sample Input I
6
20
10
15
10
30
50
4 5
1 4
5 4
3 6
2 6
Sample Output I
30

Explanation:
There are 6 people. The first person can give 20$, etc. Then, we are given 4 relationships. 1 is the relative of 4 and 5 is the relative of 4, etc. We are asked the amount that is collected for person 5. Two relatives are given for person 5: 1 and 4. And they can give totally 30$.



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

www.contester.ru