#P5151. Permutation Game
Permutation Game
Permutation Game
There are \( n \) seats labeled from \(1\) to \( n \) and \( n \) kids numbered from \(1\) to \( n \). Initially, each kid \( i \) sits on seat \( i \). The game is described by a permutation \( A = (A_1, A_2, \ldots, A_n) \). In one round, for every \( 1 \le i \le n \), the kid sitting in seat \( i \) moves to seat \( A_i \).
After \( k \) rounds, determine which kid is sitting on each seat \( 1, 2, \ldots, n \). In other words, print the kid numbers in the order of seats 1 through \( n \) at the end of the game.
inputFormat
The first line contains two integers \( n \) and \( k \), separated by a space. The second line contains \( n \) integers \( A_1, A_2, \ldots, A_n \), which represent a permutation of \( \{1, 2, \ldots, n\} \).
outputFormat
Output a single line containing \( n \) integers. The \( i \)-th integer indicates the number of the kid sitting on seat \( i \) after \( k \) rounds.
sample
3 1
3 1 2
2 3 1
</p>