#P2680. [NOIP 2015 提高组] 运输计划

    ID: 1701 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论2015NOIp 提高组最近公共祖先,LCA树链剖分,树剖

[NOIP 2015 提高组] 运输计划

Description

In the year 20442044, humanity entered the cosmic era.

Country L has nn planets and n1n-1 bidirectional routes. Each route is built between two planets, and these n1n-1 routes connect all the planets in Country L.

Xiao P runs a logistics company that has many transportation plans. Each plan is as follows: a cargo spaceship needs to travel from planet uiu_i to planet viv_i along the fastest space route. Obviously, traversing a route takes time. For route jj, any spaceship takes time tjt_j to traverse it, and any two spaceships do not interfere with each other.

To encourage technological innovation, the king of Country L allows Xiao P’s logistics company to participate in route construction, that is, to transform one route into a wormhole. Traversing the wormhole takes no time.

Before the wormhole is completed, Xiao P’s company has already pre-booked mm transportation plans. After the wormhole is completed, these mm plans will start simultaneously, and all spaceships depart together. When all mm plans are completed, Xiao P’s company finishes this phase of work.

If Xiao P can freely choose which route to convert into a wormhole, find the minimum time required for the company to complete this phase of work.

Input Format

The first line contains two positive integers n,mn, m, representing the number of planets in Country L and the number of transportation plans pre-booked by Xiao P’s company. Planets are numbered from 11 to nn.

The next n1n-1 lines describe the construction of the routes. The ii-th line contains three integers ai,bia_i, b_i, and tit_i, indicating that the ii-th bidirectional route is built between planets aia_i and bib_i, and any spaceship takes time tit_i to traverse it.

The next mm lines describe the transportation plans. The jj-th line contains two positive integers uju_j and vjv_j, indicating that the jj-th plan is to travel from planet uju_j to planet vjv_j.

Output Format

Output one integer, the minimum time required for Xiao P’s logistics company to complete this phase of work.

6 3 
1 2 3 
1 6 4 
3 1 7 
4 3 6 
3 5 5 
3 6 
2 5 
4 5
11

Hint

The Constraints and characteristics of all testdata are shown in the table below.

Test point ID n=n = m=m = Convention
1 100100 11
2 ^ 100100 The ii-th route connects planet ii and planet i+1i + 1.
3 ^
4 20002000 11 ^
5 10001000 The ii-th route connects planet ii and planet i+1i + 1.
6 20002000 ^
7 30003000
8 10001000
9 20002000 ^
10 30003000
11 8000080000 11
12 100000100000 ^
13 7000070000 The ii-th route connects planet ii and planet i+1i + 1.
14 8000080000 ^
15 9000090000
16 100000100000
17 8000080000
18 9000090000 ^
19 100000100000
20 300000300000
All testdata 1ai,bi,uj,vjn1 \le a _ i, b _ i, u _ j, v _ j \le n0ti10000 \le t _ i \le 1000

Please pay attention to the impact of constant factors on program efficiency.

Translated by ChatGPT 5