F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tower Attack

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 643    Accepted Submission(s): 68


Problem Description
There was a civil war between two factions in Skyrim, a province of the Empire on the continent of Tamriel. The Stormcloaks, led by Ulfric Stormcloak, are made up of Skyrim’s native Nord race. Their goal is an independent Skyrim free from Imperial interference. The Imperial Legion, led by General Tullius, is the military of the Empire that opposes the Stormcloaks and seeks to reunite and pacify the province.
The current target of Ulfric Stormcloak is to attack Whiterun City, which is under controlled by General Tullius. Near by this city there are N towers under the Empire’s control. There are N - 1 roads linking these towers, so soldiers can move from any tower to another one through these roads.
In military affairs, tactical depth means the longest path between two of all towers. Larger the tactical depth is, more stable these towers are.
Your mission, should you choose to accept it. In each turn, Ulfric tells you two roads. You need to figure out the tactical depth after destroying these two roads.
 

Input
The first line of input contains an integer t which is the number of test cases. Then t test cases follow. For each test case, the first line contains two integers N(N ≤ 100000), representing the number of towers, and Q(Q ≤ 100000), represeting the number of queries.
In the next N - 1 lines, the i-th line describes the i-th road and contains three integers u, v and w (0 ≤ w ≤ 5000) corressponding to a path between u and v of length w.
In the next Q lines, each line contains two integers u and v representing that the u-th road and the v-th road would be destroyed in this turn. It is guaranteed that u $\neq$ v.
 

Output
For each query, output the tactical depth.
 

Sample Input
1 8 3 2 1 7 3 1 7 4 2 5 5 2 6 4 6 3 7 2 8 1 8 2 4 6 2 3 5 6
 

Sample Output
22 17 20
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 07:14:43, Gzip enabled