#P17395. [ICPC 2018 Shenyang R] Diameter of a Tree
[ICPC 2018 Shenyang R] Diameter of a Tree
Problem Description
Given a weighted tree , we define its diameter as the length of the longest path between two vertices on it, where the length of a path is equal to the sum of weights of edges in the path.
If the tree stretches like a spider or a yawning tiger, its diameter will change. Let's use to denote the state of the tree after seconds, at which time the weight of each edge has been increased by exactly units from .
You will be presented with several different queries, and you should calculate the tree's diameter at some specified time for each query.
Input Format
The input contains several test cases, and the first line contains a positive integer indicating the number of test cases which is up to .
For each test case, the first line contains two integers and indicating the number of vertices in the tree and the number of given queries respectively, where and .
Each of the following lines contains three integers and which represent an edge in the original tree between the -th vertex and the -th one of weight , where , and .
Each of the following lines describes a query containing only one integer that asks you to calculate the diameter of the tree , where .
We guarantee that the sum of in all test cases is no larger than , and the sum of in all test cases is no larger than as well.
Output Format
For each test case, output a line containing "Case #x:" (without quotes) at first, where is the test case number starting from .
Then output lines corresponding to all queries. The -th line of them contains an integer indicating the answer to the -th query.
2
3 3
1 2 1
1 3 5
5
10
100
5 6
1 2 100
2 3 5
2 4 1
4 5 1
0
1
2
3
4
5
Case #1:
16
26
206
Case #2:
105
107
109
111
114
117
Hint
In the second sample case:
- the diameter of is , which is the length of the path ; and
- the diameter of is , which is the length of the path .