FlexportOA #8
Throw The Ball
Estimated MediumJudge-ready
Topics (AI-labelled)HashingSimulation
Starting with friend 1, each second the ball is passed to the friend specified by receiver. Find who holds the ball after the given number of seconds.
Input
The first line contains n and k (2≤n≤100000, 1≤k≤10^12); the second line contains n receiver indices (each in 1..n and different from the corresponding sender).
Output
Output the 1-based index of the friend holding the ball after k seconds.
Example 1
Input:
5 6
2 4 1 5 3
Output:
2
Example 2
Input:
5 2001
2 4 1 5 3
Output:
2
Example notes
A linear scan/dynamic programming solution follows directly from the rules; the examples have been checked one by one against an independently built oracle.
Editorial
Loading solution…