Save Winterfell
Submissions: 1099   Accuracy:

15.86%

  Difficulty: Medium   Marks: 4

As White Walkers have attacked winterfell,Cersei has to send her army to winterfell but through tunnels.
Unwilling to do so, she wants to delay as much as she can so she take longest route to Winterfell.
You are given no of tunnels(n) followed by tunnel 'u' connecting tunnel 'v' having distance 'w'. 
Now,you being fan of Cersie, is keen to find the longest route.

Input:
The first line of input contains the number of testcases t.
The first line of each testcase contains the number of tunnels (n). Each 'n-1' lines contain 'u','v' and 'w' denoting that tunnel 'u' and 'v' are connected and distance between them is 'w'.

Output:
For each test case print the length of longest route.

Constraints:
1<=t<=1000
1<=n<=7000
1<=u,v<=n
1<=w<=500

Example:
Input:
1
8
1 5 3
3 5 4
5 4 2
2 4 5
4 7 6
7 8 2
7 6 1
Output: 
14

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: chunky_2808
Author: Chunky_2808


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.