Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. 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$.
Для отправки решений необходимо выполнить вход.
|