#P3761. [TJOI2017] 城市

    ID: 1327 远端评测题 3000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2017各省省选枚举,暴力树的直径天津

[TJOI2017] 城市

Description

After graduating from the Urban Planning program at Gariton University, Xiao Ming joined a regional Urban Planning Bureau. This region has nn cities and n1n-1 highways, ensuring that any two cities are mutually reachable via highways. However, traveling through a highway requires paying a transportation cost. After careful study, Xiao Ming thinks the transportation cost in this region is too high.

Xiao Ming wants to completely overhaul the region, but due to limited resources from his supervisor, he can only modify exactly one highway. The modification is to remove one highway and rebuild one identical highway (i.e., with the same transportation cost), so that the maximum transportation cost between any two cities is minimized (that is, the transportation cost between the pair of cities with the largest cost is as small as possible), and it must still be guaranteed that any two cities remain mutually reachable after reconstruction. If you were Xiao Ming, how would you solve this problem?

Input Format

The first line contains an integer nn, the number of cities.

The next n1n-1 lines describe the initial n1n-1 highways. Each line contains three integers u,v,du, v, d. Here u,vu, v are the labels of the two endpoint cities of this highway, and dd is its transportation cost.

1u,vn1 \leq u, v \leq n, 1d20001 \leq d \leq 2000.

Output Format

Output a single integer: after the optimal reconstruction, the maximum transportation cost between any two cities.

5
1 2 1
2 3 2
3 4 3
4 5 4
7

Hint

For 30% of the testdata, 1n5001 \leq n \leq 500.

For 100% of the testdata, 1n50001 \leq n \leq 5000.

Translated by ChatGPT 5