#P10147. [Ynoi1999] 56TP
[Ynoi1999] 56TP
Background

Problem Description
You are given a rooted tree with vertices. Each vertex has a weight at time .
For each vertex, is given. It is guaranteed that for any non-leaf node , , and for any leaf node , .
There are queries. Each query gives , asking for the minimum value, maximum value, and sum of the weights at time along the path from to .
For a leaf node , .
For a non-leaf node with , is the maximum of over all children of .
Input Format
The first line contains two integers .
The next lines each contain one integer, in order, representing , where denotes the parent of node , and the root is .
The next lines each contain one integer, in order, representing .
The next lines each contain three integers representing .
Output Format
Output lines. Each line contains one integer, which is the answer to the corresponding query.
8 3
1
2
3
3
3
4
4
0
0
0
0
7
5
7
5
7 5 8
1 2 8
8 2 8
7 7 28
7 7 14
5 7 26
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
For of the testdata, , , , .
Translated by ChatGPT 5