cswork / OA打开练习工作台

FlexportOA #8

Throw The Ball

估计中等可在线判题

考点(AI 标注)哈希计数模拟/实现

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.

输入格式

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 the 1-based index of the friend holding the ball after k seconds.

样例 1

输入:

5 6
2 4 1 5 3

输出:

2

样例 2

输入:

5 2001
2 4 1 5 3

输出:

2

样例说明

A linear scan/dynamic programming solution follows directly from the rules; the examples have been checked one by one against an independently built oracle.