問題

abc030.contest.atcoder.jp

解法

python 多倍長最高で通します。

N, a = map(int, raw_input().split())
a -= 1
k = input()
b = map(int, raw_input().split())
for i in range(N):
    b[i] -= 1

used = [-1]*N
step = [-1]*N
cur = a
loop = 0
cnt = 0
while (True):
    if (used[cur] == -1):
        used[cur] = cnt
        step[cnt] = cur
        cnt += 1
        cur = b[cur]
    else:
        loop = cnt-used[cur]
        break

if k <= used[cur]:
    print step[k]+1
else:
    k -= used[cur]
    k %= loop
    print step[used[cur]+k]+1