CC On The Tree

Time Limit: 1000ms
Memory Limit: 65536KB
This problem will be judged on HDU. Original ID: 3848
64-bit integer IO format: %I64d      Java class name: Main

Description

CC lives on the tree which has N nodes.On every leaf of the tree there is an apple(leaf means there is only one branch connect this node ) .Now CC wants to get two apple ,CC can choose any node to start and the speed of CC is one meter per second.
  now she wants to know the shortest time to get two apples;

Input

Thers are many cases;
  The first line of every case there is a number N(2<=N<=10000)
if n is 0 means the end of input.
Next there is n-1 lines,on the i+1 line there is three number ai,bi,ci
which means there is a branch connect node ai and node bi.
(1<=ai, bi<=N , 1<=ci<=2000)
ci means the len of the branch is ci meters ;

Output

print the mininum time to get only two apple;

Sample Input

7
1 2 1
2 3 2
3 4 1
4 5 1
3 6 3
6 7 4
0

Sample Output

5

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .