当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6394:Tree

题目描述
Alice and Bob are playing with a magic tree This magic tree has $n$ nodes,with $n - 1$ 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 $\text{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 $\text{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 contains multiple tests
The first line contains one integer $T(T \leq 4)$, 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(n \leq 100000)$, indicating the size of the magic tree.
The second line has $n - 1$ numbers, and the ith number represents the father of the node $i+1$.
The third row has $n$ numbers, and the $\text{ith}$ number represents the initial mana $a_{i}(a_{i} \leq n)$ value of each node.
In the fourth line, a number $m(m \leq 100000)$ represents the number of operations.
The next $m$ lines, one operation per line.
First a number $\text{op}(1 \leq \text{op} \leq 2)$ represents the type of operation.
If $\text{op} = = 1$, a number $x$ will be read immediately, indicating that a magic stone is thrown to the node $x$.
If $\text{op} = = 2$, it will immediately read in two numbers $x$ and $\text{new_a}$, indicating that the magic value of node $x$ is modified to $\text{new_a}(\text{new_a} \leq n)$.
输出解释
For each query with $\text{op} = = 1$, output the answer
输入样例
1
4
1 2 3
1 1 1 1
3
1 4
2 3 2
1 4
输出样例
4
3

提示
For the first query: 4-\>3-\>2-\>1-\>out
For the second query:4-\>3-\>1-\>out
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6394

最后修改于 2020-10-25T23:30:57+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)