import sys,math
input = sys.stdin.readline
N,K,M = map(int,input().split())
student = [*map(int,input().split())]
sparse = [[0]+[*map(int,input().split())]]+[[0]*(K+1) for i in range(30)]
for i in range(1,31):
for k in range(1,K+1):
sparse[i][k] = sparse[i-1][sparse[i-1][k]]
for i in range(31):
if (1<<i)&(M-1):
for n in range(N):
student[n] = sparse[i][student[n]]
print(*student)
기본적인 sparse-table 문제이다.
sparse-table이 가장 기초적인 수준의 문제라서 sparse-table 알고리즘을 알고 있다면 쉽게 해결할 수 있다.