#P5151. HKE与他的小朋友

HKE与他的小朋友

Description

There are nn seats numbered 11 to nn, and the children are also numbered 11 to nn. Initially, every child sits in the seat with the same number. The game of HKE can be described by an nn-permutation A(A1,A2,,An)A(A_1, A_2, \cdots, A_n). In one round, for every 1in1\leq i\leq n, the child sitting at position ii moves to position AiA_i.

After kk rounds, HKE wants to know which child ends up at positions 1,2,,n1, 2, \cdots, n.

Input Format

The first line contains two integers n,kn, k. The second line contains a permutation A1,A2,,AnA_1, A_2, \cdots, A_n.

Output Format

Output one line with nn numbers denoting the child at positions 1,2,,n1, 2, \cdots, n.

5 5
2 3 1 5 4
2 3 1 5 4
5 4
2 3 1 5 4
3 1 2 4 5

Hint

  • For 30%30\% of the testdata, n1000n\leq1000, k1000k\leq1000.
  • For 100%100\% of the testdata, n100000n\leq100000, k2311k\leq2^{31}-1.

Translated by ChatGPT 5