#P1099. [NOIP 2007 提高组] 树网的核
[NOIP 2007 提高组] 树网的核
Description
Let be a connected undirected graph without cycles (also called an unrooted tree), where each edge has a nonnegative integer weight. We call a "treenetwork". Here and denote the sets of nodes and edges, respectively, denotes the set of edge lengths, and has nodes.
Path: In a treenetwork, there is a unique simple path between any two nodes and . Let denote the length of the path whose endpoints are and , i.e., the sum of the lengths of the edges on that path. We call the distance between nodes and .
, where ranges over the nodes on path .
Diameter of a treenetwork: The longest path in a treenetwork is called its diameter. For a given treenetwork , the diameter is not necessarily unique, but it can be proved that the midpoint of any diameter (which may lie in the interior of an edge rather than exactly at a node) is unique; we call this point the center of the treenetwork.
Eccentricity : The distance from the farthest node in to path , namely
Task: Given a treenetwork and a nonnegative integer , find a path which is a subpath on some diameter (the endpoints of this path are both nodes in the treenetwork), whose length does not exceed (it may equal ), such that the eccentricity is minimized. We call such a path the "Core" of treenetwork . If necessary, may degenerate into a single node. In general, under the above definition, the core is not necessarily unique, but the minimal eccentricity is unique.
The following figure gives an example of a treenetwork. In the figure, and are two diameters, both of length . Point is the center of the treenetwork, and the length of edge is . If is specified, then the core of the treenetwork is path DEFG (it can also be taken as path DEF), and the eccentricity is . If (or , ), then the core of the treenetwork is node , and the eccentricity is .

Input Format
There are lines in total.
Line : two positive integers and , separated by a single space. Here is the number of nodes in the treenetwork, and is the upper bound on the length of the core. The nodes are numbered .
Lines through : each line contains three space-separated integers , indicating an edge between nodes and with length . For example, 2 4 7 means the edge connecting nodes and has length .
Output Format
Output a single nonnegative integer: the minimal eccentricity under the given definition.
5 2
1 2 5
2 3 2
2 4 4
2 5 3
5
8 6
1 3 2
2 3 2
3 4 6
4 5 3
4 6 4
4 7 2
7 8 3
5
Hint
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , , .
NOIP 2007 Senior Problem 4.
Translated by ChatGPT 5
京公网安备 11011102002149号