View Single Post
Old 08-03-2005, 06:35 PM   #22
Unknown Hero
Home Sweet Abandonia

 
Join Date: Aug 2004
Location: Split, Croatia
Posts: 1,028
Default

2. Exam
Luka dislikes learning, but anyways, he will like to pass the most difficulty exam on the first year. During his last visit to university's canteen, he overheard that all students of second year know which questions will be in his exam. The truth is that no one actually knows it, but everyone thinks that someone else knows.
Luka now chooses person A from the second year and asks him what questions will be in the exam. Person A responds that he doesn't know, but that he thinks that person B knows. Then Luka asks the same question to person B, etc.
Write a program that will determine which student Luka should first ask about the exam, so that the number of questioned students is the biggest possible.

Entering parameters:
In the first line there is a whole number N, 2<=N<=1000, the number of students. Students are marked with numbers from 1 to N.
In every of next N lines there is one number. First number determines ordinal number of student that first student will send Luka to ask him about the exam, second number determines ordinal number of student that second student will send Luka to ask him about Exams, and so on.

Exiting parameters:
In first and only line write an ordinal number of student that Luka have to ask first about the exam, so that the number of students that he will meet on that way could be the biggest possible.
If there are more these students, then write a number of that student that has the smallest ordinal number.

Test examples:
exam.in
3
3
3
1
exam.out
2

exam.in
4
2
3
4
1
exam.out
1

exam.in
6
2
3
4
3
1
1
exam.out
5




Two more to go. I will post those two after at least one of members tries to solve one or both of previous two exams. k:
Unknown Hero is offline                         Send a private message to Unknown Hero
Reply With Quote