编程介的小学生 2019-03-28 19:48 采纳率: 20.5%
浏览 132

分型树的一个算法的综合的使用问题解决,怎么使用C语言程序的设计思路来实现

Problem Description
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.

Input
The first line of the input is a single integer T(T≤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≤n≤50000,1≤q<100000).

The second line contains n−1 integers Ai(1≤Ai≤i) represent the node i+1's father is node Ai.

The third line contains n integers Bi(1≤i≤n,0≤Bi≤1000) represent the node i's weight is Bi.

Then q line follow,each line contains two integers u,v,it represents a query(1≤u,v≤n).

Output
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)

Sample Input
1
5 1
1 2 3 4
413 127 263 869 960
1 5

Sample Output
1373 960

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题