HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN111 Homeworks 2013-2015 > problem:


15-FallHW-3. 50822 - Linked List

CEN111 Homeworks 2013-2015

Start: Jan.10.2015 at 10:00:00 AM
Finish: Jan.10.2015 at 03:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 14-Fall2-50. 50534 - Top Trading C...
• 14-Fall2-60. 50487 - Radius of Inscr...
• 14-FallResit-20. 50407 - Missing Nu...
• 14-Spr2-10. 50426 - Calculating Sales
• 14-Spr2-20. 50425 - Calculating W...
• 14-Spr2-30. 50445 - Cryptography
• 14-Spr2-50. 50437 - Age Labeling
• 15-FallHW-2. 50821 - Derivative of ...
• 15-FallHW-3. 50822 - Linked List
• 15-FallHW-4. 50823 - Secret Number
• 15-FallHW-5. 50824 - Sum of Group...
• 15-FallHW-6. 50825 - Drawing Polygon
• 15-FallPr-10. 50808 - Total Distance...
• 15-FallPr-50. 50812 - Total Discount...
• 15-FallPr-70. 50814 - Buying Books f...
• 15-FallPr-80. 50815 - Breaking the ...
• 15-FallRE-10. 50853 - Parking Place

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.

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

  1. the 5th number: 2
  2. The fifth number is linked to the second number: 5
  3. The second number is linked to the 4th number: 6 (qth visited number)
  4. 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.



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

www.contester.ru