Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Question by Ibrahim Mesecan.
Linked List
You are given an integer list. Then you are
given another integer list which shows the links
between the numbers. The numbers in the first
list show the original list. The second list
shows the links. For example, according to the
example on the left, the first number is the
5th number. Then, 5th
number is linked to the second number, etc.
Question:
Write a program that is going to get information for n
numbers and prints the sum of pth
and qth visited numbers in the linked list.
Input specification
In the first line you will be given three integers:
- the number of numbers (n) and
- order of the numbers (p and q) we are searching for
Then in the following line you will be given n
numbers (links of the numbers) And in the last
line you will be given n numbers where 0 ≤ n
≤ 20,000; 1 ≤ (p and q) ≤ n; and
each number in the list are between -3e4 and 3e4.
Note: Assume that number positions
are from 1 to n.
Output specification:
Show just one number: sum of pth
and qth numbers.
Sample Input I
5 4 3
5 4 1 3 2
9 5 8 6 2
|
Sample Output I
14
|
Explanation: The numbers start with
- the 5th number: 2
- The fifth number is linked to the second number: 5
- The second number is linked to the 4th number: 6
(qth visited number)
- And it’s linked to the 3rd number: 8
(pth visited number)
So, the third and fourth numbers are 6 and 8, and the sum is 14.
Для отправки решений необходимо выполнить вход.
|