#P1099. [NOIP 2007 提高组] 树网的核

    ID: 99 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟动态规划,dp树形结构2007NOIp 提高组枚举,暴力最短路

[NOIP 2007 提高组] 树网的核

Description

Let T=(V,E,W)T=(V, E, W) be a connected undirected graph without cycles (also called an unrooted tree), where each edge has a nonnegative integer weight. We call TT a "treenetwork". Here VV and EE denote the sets of nodes and edges, respectively, WW denotes the set of edge lengths, and TT has nn nodes.

Path: In a treenetwork, there is a unique simple path between any two nodes aa and bb. Let d(a,b)d(a, b) denote the length of the path whose endpoints are aa and bb, i.e., the sum of the lengths of the edges on that path. We call d(a,b)d(a, b) the distance between nodes aa and bb.

D(v,P)=min{d(v,u)}D(v, P)=\min\{d(v, u)\}, where uu ranges over the nodes on path PP.

Diameter of a treenetwork: The longest path in a treenetwork is called its diameter. For a given treenetwork TT, 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 ECC(F)\mathrm{ECC}(F): The distance from the farthest node in TT to path FF, namely

ECC(F)=max{D(v,F),vV}.\mathrm{ECC}(F)=\max\{D(v, F), v \in V\}.

Task: Given a treenetwork T=(V,E,W)T=(V, E, W) and a nonnegative integer ss, find a path FF which is a subpath on some diameter (the endpoints of this path are both nodes in the treenetwork), whose length does not exceed ss (it may equal ss), such that the eccentricity ECC(F)\mathrm{ECC}(F) is minimized. We call such a path the "Core" of treenetwork T=(V,E,W)T=(V, E, W). If necessary, FF 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, A ⁣ ⁣BA\!-\!B and A ⁣ ⁣CA\!-\!C are two diameters, both of length 2020. Point WW is the center of the treenetwork, and the length of edge EFEF is 55. If s=11s=11 is specified, then the core of the treenetwork is path DEFG (it can also be taken as path DEF), and the eccentricity is 88. If s=0s=0 (or s=1s=1, s=2s=2), then the core of the treenetwork is node FF, and the eccentricity is 1212.

Input Format

There are nn lines in total.

Line 11: two positive integers nn and ss, separated by a single space. Here nn is the number of nodes in the treenetwork, and ss is the upper bound on the length of the core. The nodes are numbered 1,2,,n1, 2, \dots, n.

Lines 22 through nn: each line contains three space-separated integers u,v,wu, v, w, indicating an edge between nodes uu and vv with length ww. For example, 2 4 7 means the edge connecting nodes 22 and 44 has length 77.

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 40%40\% of the testdata, it is guaranteed that n15n \le 15.
  • For 70%70\% of the testdata, it is guaranteed that n80n \le 80.
  • For 100%100\% of the testdata, it is guaranteed that 2n3002 \le n \le 300, 0s1030 \le s \le 10^3, 1u,vn1 \le u, v \le n, 0w1030 \le w \le 10^3.

NOIP 2007 Senior Problem 4.

Translated by ChatGPT 5