Faster Networks

A general network system can be described as an undirected graph. Each node on the graph is a server, and the data lines connecting the servers are treated as an edge on the graph. The edge weight is the length of the data line. The communication distance between the two servers is defined as the shortest path length between their corresponding nodes. Now, consider a network system where the graph structure is a tree. You are the administrator of the network system and are required to add a data line of a given length to the system. Data lines can be connected to any two servers. Your task is to find the minimum distance between two servers where the communication distance is farthest in all legitimate scenarios (all ways of adding the data line). Input The input contains multiple sets of data. For each set of data, the first row of input contains two positive integers N (0 < N ≤ 100000), where N is the number of servers and L is the length of the newly added data line. This is followed by N − 1 lines, each with three positive integers a, b, l, which means there is a data line with length l connected to the servers a and b. The server number is indexed from 1, ..., N. Both l, and L fit in 32 bit signed integer. The last input set is just 2 ‘0’s on one line (denoting end of all inputs), and should be ignored (no output for this). Output For each set of data, output on one line the minimum distance between two servers where the commu- nication distance is farthest in all legitimate scenarios. Sample Input 31 121 131 71 121 231 341 451 561 671 00 Sample Output 1 3