#P2491. [SDOI2011] 消防

    ID: 1505 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2011二分各省省选山东广度优先搜索,BFS树的直径

[SDOI2011] 消防

Description

There are nn cities in a country. Any two of these nn cities are connected and have a unique path between them. Each road connecting two cities has length ziz_i.

The people of this country have a passion for flames beyond the universe, so the most prosperous industry is firefighting. Since the gov%ernment cannot tolerate the people's enthusiasm (massive firefighting budget expenditure) yet can do nothing about it (public support in presidential elections), they can only try every means to improve firefighting capacity.

Now the country's budget is sufficient to build a firefighting hub along a path (with both endpoints being cities) whose total length is no more than ss. To maximize the hub's utilization, it is required to minimize the maximum distance from all other cities to this path.

You are assigned to oversee this project, and of course you need to know where to place the hub.

Input Format

The input contains nn lines:

  • Line 11: two positive integers nn and ss, separated by a space. Here nn is the number of cities, and ss is the upper bound on the path length. Nodes are numbered 1,2,,n1,2,\ldots,n.
  • From line 22 to line nn: each line gives 33 positive integers, representing the two endpoints and the length of one edge. For example, 2 4 7 means the length of the edge connecting nodes 22 and 44 is 77.

Output Format

Output a single non-negative integer, which is the minimal possible value of the maximum distance from any city to the chosen path.

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 20%20\% of the testdata, n300n \le 300.

For 50%50\% of the testdata, n3×103n \le 3 \times 10^3.

For 100%100\% of the testdata, 1n3×1051 \le n \le 3 \times 10^5, 0zi1030 \le z_i \le 10^3.


2024/1/28 added a set of hack testdata.

Translated by ChatGPT 5