You have a rooted tree containing \(n\) vertexes. Let's index these tree vertexes with integers from \(1\) to \(n\). The tree root is vertex \(1\).
Each vertex (except for the tree root) \(v\) has a direct ancestor \(p_v\). Also, each vertex \(v\) has an integer value \(s_v\).
Your are to perform the following queries:
The first line of the input contains an integer \(n\) \((2 \leq n \leq 50000)\) — the number of tree vertexes.
The second line contains \(n - 1\) integers \(p_2, p_3, ..., p_n\) \((1 \leq p_i \leq n)\) — the direct ancestor of every vertex. It is guaranteed that these edges form a tree.
The third line contains \(n\) integers — \(s_1, s_2, ... s_n\) \((0 \leq s_i \leq 10^6)\) — the values written on each vertex of the tree.
The next line contains an integer \(q\) \((1 \leq q \leq 50000)\) — the number of queries. Each of the following \(q\) lines contains the description of a query in the format described in the statement. It is guaranteed that query arguments \(u\) and \(v\) lie between \(1\) and \(n\). It is guaranteed that argument \(t\) in the queries of type \(V\) meets limits \(0 \leq t \leq 10^6\).
Print \(q + 1\) lines each containing a real number — the corresponding expected values. Your answer will be considered correct if its absolute or relative error doesn't exceed \(10^{-6}\).
Subtask # | Score | Constraints |
---|---|---|
1 | 11 | \(n, q \leq 200\) |
2 | 23 | \(n, q \leq 2000\) |
3 | 22 | All queries will be of type V. |
4 | 24 | \(n, q \leq 25000\) |
5 | 20 | No additional constraints |
Sample Input 1 | Sample Output 1 |
5
|
1.640000000
|
Note that in the query P \(v\) \(u\), if \(u\) lies in subtree of \(v\) you must perform the assignment \(p_u = v\). An example of such a case is the last query in the sample.
Subtask | Score |
---|---|
1 | 11 |
2 | 23 |
3 | 22 |
4 | 24 |
5 | 20 |
6 | 0 |