题目描述
Problem Description
Mikami is using a suspicious English dictionary. The dictionary contains the meanings of $ N $ words, and the explanation for word $ i $ simply states "has the same meaning as word $ b_i $." Here, we refer to the $ i $-th word as word $ i $. Since Mikami doesn't know any English words yet, when he tries to look up the meaning of word $ i $, he will attempt to look up the meaning of word $ b_i $. Mikami is diligent and will continue to use the dictionary in the same manner even if he has already tried to look up a word before. Unfortunately, since the dictionary does not actually write down the meanings of the English words, he cannot learn the meanings. We define one step as the process of Mikami trying to look up the meaning of word $ i $, referring to the dictionary, and then attempting to look up the meaning of word $ b_i $.
After $ k $ steps of Mikami trying to look up the meaning of word $ i $, which word will he be trying to look up?
Input & Output Format
The input is given from the standard input in the following format:
$ N $ $ a $ $ k $ $ b_1 $ $ b_2 $ … $ b_N $
- The first line contains the number of words $N\ (2\ ≦\ N\ ≦\ 10^5)$ and the number of the word Mikami is trying to look up $a\ (1\ ≦\ a\ ≦\ N)$, separated by spaces.
- The second line contains the number of steps Mikami will take to look up the word $k(1\ ≦\ k\ ≦\ 10^{100000})$.
- The third line contains $ N $ integers $ b_1,...,b_N $ representing the explanations for each word, separated by spaces.
- It is guaranteed that $1\ ≦\ b_i\ ≦\ N$ and $b_i\ ≠\ i\ (1\ ≦\ i\ ≦\ N)$.
Input Format
None
Output Format
Output the number of the word Mikami will be trying to look up after $ k $ steps starting from word $ a $ on one line. Ensure a newline at the end of the output.
Sample Input and Output
Sample Input #1
6 4
5
2 3 1 2 6 5
Sample Output #1
3
Sample Input #2
4 1
100000000000000000000
2 3 4 1
Sample Output #2
1
Sample Input #3
8 1
1
2 3 4 5 3 2 4 5
Sample Output #3
2
Notes/Hints
Partial Points
This problem has partial scoring:
- If you solve the dataset where $k\ ≦\ 10^{18}$, you will be awarded $ 50 $ points.
Sample Explanation 1
Mikami looks up the words as follows in each step: In step 1, to find the meaning of word 4, he tries to look up word 2. In step 2, to find the meaning of word 2, he tries to look up word 3. In step 3, to find the meaning of word 3, he tries to look up word 1. In step 4, to find the meaning of word 1, he tries to look up word 2. In step 5, to find the meaning of word 2, he tries to look up word 3. Therefore, after 5 steps, Mikami is trying to look up word 3.
Sample Explanation 2
$ k $ can be very large.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分