#P12462. [Ynoi Easy Round 2018] 星野爱久爱海
[Ynoi Easy Round 2018] 星野爱久爱海
Background

Problem Description
Hoshino Akua gives you a tree with edge weights .
Define the weight of as .
Define to be a connected subtree of if and only if is a tree, , and .
Define the weight of as .
Define the Steiner tree of as , where is a connected subtree.
There are queries. In the -th query, you are given . Compute $\max \{f(S) | S \subseteq \{V_{L_i},V_{L_i+1},\ldots,V_{R_i}\},|S|=k_i\}$.
Input Format
The first line contains an integer .
The next lines each contain three integers , meaning and . It is guaranteed that .
The next line contains an integer .
The next lines each contain three integers . It is guaranteed that .
Output Format
Output lines, each containing one integer, the answer to a query.
10
1 2 2
2 3 3
3 4 2
1 5 7
2 6 7
4 7 1
1 8 3
4 9 6
7 10 4
10
5 10 5
4 9 6
10 10 1
2 6 3
6 9 3
6 9 4
7 9 2
1 3 2
1 7 3
3 8 3
35
31
0
21
23
24
16
5
22
22
Hint
Idea: nzhtl1477, Solution: rushcheyo&nzhtl1477, Code: rushcheyo, Data: rushcheyo.
This problem uses subtask grading.
Let .
For all testdata, it is guaranteed that , , and .
- (15 points).
- (15 points).
- (10 points).
- (10 points).
- (15 points).
- (15 points).
- (10 points).
- No special constraints (10 points).
Translated by ChatGPT 5