Fire (tree diameter)

Title Description

A country there are n cities, any two of the n cities and there are unique communication path, each communication path length of two city zi (zi <= 1000).
People in this country have a passion beyond the universe to the flame, so the country's most thriving industry is the fire industry. As the government ran out of patience enthusiasm nationals (a large number of fire overhead expenses) but yet do nothing (the presidential campaign to support the national rate), we can only try ways to improve fire fighting capability.
Now this country funds sufficient to establish a fire on the hub side length s and not more than the path (city at both ends), in order to maximize the utilization of the hub, the distance to all other cities requires that the maximum value of minimum path .
You appointed to oversee the project, of course you need to know to establish a hub in what position.

Input Format

Comprising n input lines:
the first line, two positive integers n and s, separated by a space. Wherein n is the number of cities, s is the path length of the boundary. In this set of nodes numbered 1,2, ......, n.
From the second line to the n-th line, each line separated by a space given positive integer 3 illustrates a sequence number and length of the two end points of each edge. For example, "247" represents the length of edges connecting the nodes 2 and 4 to 7.

Output Format

Output comprising a non-negative integer, i.e. the maximum of all the cities to the selected path, of course, the maximum value of all programs must be the smallest.

Sample

Sample input

【样例输入1】
5 2
1 2 5
2 3 2
2 4 4
2 5 3
【样例输入2】
8 6
1 3 2
2 3 2 
3 4 6
4 5 3
4 6 4
4 7 2
7 8 3  

Sample Output

Sample Output
【样例输出1】
5
【样例输出2】
5

Is not a long time did not face a sticky problem.

A good question diameter of the tree.

First of all we want to find the diameter, the diameter of certain because the midpoint of the maximum minimum distance of other points,

Length provided the diameter d, assume that the other points to the midpoint of a distance greater than d / 2, it will always get a new diameter formed and endpoint

When then we can consider some out when the diameter of the diameter from the longest point, what would the point

Found, either the diameter of the end points, or non-point diameter, because the diameter of the non-point is constant, we can pre-out,

The rest of us just need to find cover in the queue monotonous path diameter less than s just fine.

 

Guess you like

Origin www.cnblogs.com/Wwb123/p/11610995.html