题目描述
Problem Description
Ringo is playing with $ N $ balloons tied with strings. The length of the string for balloon $i\ (1\ ≦\ i\ ≦\ N)$ is $ L_i $. Ringo holds the string of balloon $ 1 $ and ties the string of balloon $i\ (2\ ≦\ i\ ≦\ N)$ to balloon $ P_i $. We call this structure a "Balloon Tree".
The height of the Balloon Tree is defined as the height of the highest balloon in the tree. The height of balloon $ 1 $ is $ L_1 $, and the height of balloon $i\ (2\ ≦\ i\ ≦\ N)$ is the height of balloon $ P_i $ plus $ L_i $.
Ringo wants to adjust the height of the Balloon Tree to exactly match the height of the ceiling by untying some strings. He also wants to know the minimum number of strings that need to be untied to achieve this. When the string of balloon $i\ (2\ ≦\ i\ ≦\ N)$ is untied, balloon $ i $ and all balloons connected to it will fly away and be removed from the Balloon Tree.
There are $ Q $ possible values for the ceiling height. For each of these, find the minimum number of strings that need to be untied to make the height of the Balloon Tree exactly match the ceiling height.
Input Format
The input is given from the standard input in the following format:
$ N $ $ L_1 $ $ L_2 $ ... $ L_N $ $ P_2 $ $ P_3 $ ... $ P_N $ $ Q $ $ H_1 $ $ H_2 $ : $ H_Q $
- The first line contains an integer $N\ (2\ ≦\ N\ ≦\ 10^5)$, representing the number of balloons.
- The second line contains $ N $ integers separated by spaces. The $i\ (1\ ≦\ i\ ≦\ N)$ -th integer $L_i\ (1\ ≦\ L_i\ ≦\ 10^4)$ represents the length of the string for balloon $ i $.
- The third line contains $ N-1 $ integers separated by spaces. The $i\ (1\ ≦\ i\ ≦\ N-1)$ -th integer $P_{i+1}\ (1\ ≦\ P_{i+1}\ ≦\ i)$ indicates that Ringo tied the string of balloon $ i+1 $ to balloon $ P_i $.
- The fourth line contains an integer $Q\ (1\ ≦\ Q\ ≦\ 10^5)$, representing the number of possible ceiling heights.
- The next $ Q $ lines contain integers $H_i\ (1\ ≦\ H_i\ ≦\ 10^9)$, representing the possible ceiling heights.
Output Format
Output consists of $ Q $ lines. The $i\ (1≦i≦Q)$ -th line should contain the minimum number of strings that need to be untied to make the height of the Balloon Tree exactly $ H_i $. If it is not possible to achieve exactly $ H_i $, output $ -1 $ instead. End each output with a newline.
Sample Input and Output
Sample Input #1
5
1 1 2 2 2
1 2 2 1
2
2
3
Sample Output #1
3
1
Sample Input #2
10
10 5 6 4 2 2 3 1 1 5
1 1 2 2 3 5 7 7 2
5
10
12
15
17
21
Sample Output #2
2
-1
4
4
0
Notes/Hints
Sample Explanation 1
The figure below shows the initial Balloon Tree, the Balloon Tree with height adjusted to $ 2 $, and the Balloon Tree with height adjusted to $ 3 $. The red × marks indicate the strings that need to be untied. 
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分