PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000018. Hành trình dịch chuyển (Teleporter)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hành trình dịch chuyển (Teleporter)
Teleporter
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are towns labeled through . Town has exactly one teleporter that sends you to town .
You start in town . Which town will you occupy after using a teleporter exactly times?
The number can be enormous, and your journey may revisit towns.
Input
- The first line contains .
- The second line contains integers .
Output
Print one integer: the final town.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
4 5
3 2 4 1
Output
4
Explanation
The route is . After five teleports you are in town .