YOUTUBE - Youtube
N students are bored in computer class so they watch funny video clips on YouTube.
The site contains K popular clips, numbered 1 through N. When a video clip is watched, a list of similar video clips is displayed on the side.
Every student picks a video clip from the main page and starts watching it. After exactly one minute every student gets bored of his or her video clip, so he opens the first video clip from the list of similar clips on the side (even if he already watched that clip).
Write a program that determines for each student which video clip he will be watching during the M-th minute of the class.
The first line contains three integers N, K and M (1 ≤ N, K ≤ 100 000) (1 < M ≤ 1 000 000 000), the numbers of students, video clips and minutes.
The second line contains N integers, each between 1 and K, the indices of video clips the students start watching.
The third line contains K integers, each between 1 and K, the index of the first similar clip for each video clip.
Output N integers, the indices of video clips that students will be watching during the M-th minute.
4 5 2
1 2 4 3
5 5 1 2 3
Output: 5 5 2 1
2 6 5
2 3 4 1 4 5
Hint: think like LCA
don't spam here!!!
it can be solved without looking for cycles...
can be done without using cycles... has an easy implementation, like dat of suffix array...
giving tle with normal logic of finding cycle.. plz help..
Giving time limit error !!!! Any hints plz ....
6354341 : It is giving a seg fault after 12 judges!! kindly see it.
Don't know which test case i'm missing running fine on my pc and it's giving wrong answer.
Note: if you have a 2d array with bounds [x][y], where x > y, you can get a speed up by switching to bounds [y][x]