Tree

TimeLimit:1000MS  MemoryLimit:65536KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

Alice and Bob are playing with a magic tree This magic tree has n nodes,with n1 magic paths connecting them into a connected block. Node 1 is at the top of the magic tree (layer 0). Node i is at the kth layer, where k is the distance from the node i to the node 1. Alice and Bob give a mana value on each node. If a magic stone falls on node i, it will be sent up to the k layer and appear on the kth ancestor node of the i layer(k is the mana value of node i). This node will continue to send up it, and so on. If the layer of node i is less than k, this stone will be sent out of the magic tree. Alice is curious, she will modify the magic value of a node, and ask Bob: If you drop a magic stone on the node x, how many times does it take to transfer it out of the magic tree?

Input

Input contains multiple tests
The first line contains one integer T(T4), indicating the number of test cases.
The following lines describe all the test cases
For each test case: The first line contains an integer n(n100000), indicating the size of the magic tree.
The second line has n1 numbers, and the ith number represents the father of the node i+1.
The third row has n numbers, and the ith number represents the initial mana ai(ain) value of each node.
In the fourth line, a number m(m100000) represents the number of operations.
The next m lines, one operation per line.
First a number op(1op2) represents the type of operation.
If op==1, a number x will be read immediately, indicating that a magic stone is thrown to the node x.
If op==2, it will immediately read in two numbers x and new_a, indicating that the magic value of node x is modified to new_a(new_an).

Output

For each query with op==1, output the answer

SampleInput
1
4
1 2 3
1 1 1 1
3
1 4
2 3 2
1 4
SampleOutput
4
3

 Hint For the first query: 4-\>3-\>2-\>1-\>out For the second query:4-\>3-\>1-\>out
Submit
题目统计信息详细
总AC数5
通过人数4
尝试人数4
总提交量5
AC率80.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签
出处

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: