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

建议使用的浏览器:

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

5436:Transmigration tree

题目描述
There is a tree, $n$ nodes, numbered from $1$ to $n$, each node has a weight, but each leaf node is the father of the root,

we call such a tree as Transmigration tree, The root of each tree is node $1$.

We need to minimize the sum of weights that node $u$ to node $v$ and know who is the biggest weights node in this path.
输入解释
The first line of the input is a single integer $T (T \leq 10)$, indicating the number of testcases.

Then $T$ testcases follow.In each testcase,

The first line contains two integers $n,q$, the number of nodes and inquiry$(2 \leq n \leq 50000, 1 \leq q < 100000)$.

The second line contains $n - 1$ integers $A_i ( 1 \leq A_i \leq i )$ represent the node $i + 1$'s father is node $A_i$.

The third line contains $n$ integers $B_i ( 1 \leq i \leq n, 0 \leq B_i \leq 1000)$ represent the node $i$'s weight is $B_i$.

Then $q$ line follow,each line contains two integers $u,v$,it represents a query$(1 \leq u,v \leq n)$.
输出解释
For each query,we should output one line "$x \ y$", where $x$ is the smallest the sum of weights that node $u$ to node $v$ and $y$ is the weight of the biggest weights node in this path.(If there are multiple paths, please calculating the maximum node weights largest)
输入样例
1
5 1
1 2 3 4
413 127 263 869 960
1 5
输出样例
1373 960
来自杭电HDUOJ的附加信息
Recommend hujie

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

源链接: HDU-5436

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

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 131072/131072K(Java/Others)