Pass the Ball!
题号:NC236066
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

There are n children playing with n balls. Both children and balls are numbered from 1 to n.
Before the game, n integers are given. In each round of the game, child i will pass the ball he possesses to child p_i. It is guaranteed that no child will pass his ball to himself, which means . Moreover, we also know that after each round, each child will hold exactly one ball.
Let b_i be the ball possessed by child i. At the beginning of the game, child i () will be carrying ball i, which means initially. You're asked to process q queries. For each query you're given an integer k and you need to compute the value of after k rounds.

输入描述:

There is only one test case for each test file.
The first line of the input contains two integers n () and q (), indicating the number of children and the number of queries.
The second line contains n integers () indicating how the children pass the balls around.
For the following q lines, the i-th line contains one integer k_i () indicating a query asking for the result after k_i rounds.

输出描述:

For each query output one line containing one integer indicating the answer.
示例1

输入

复制
4 4
2 4 1 3
1
2
3
4

输出

复制
25
20
25
30

备注:

The sample test case is explained below.