#P11095. [ROI 2021] 旅行 (Day 2)
[ROI 2021] 旅行 (Day 2)
Problem Description
Translated from ROI 2021 D2T4.
Sky decided to become a travel content creator and publish travel videos from cities all over the country. This country has cities, numbered from to . City is the capital. There are undirected roads between the cities, numbered from to , and each road connects two different cities. At the same time, the same pair of cities may be connected by multiple different roads. From any city, it is possible to reach any other city by roads.
Sky and Aqua cannot be separated, so Sky plans to start from the capital together with Aqua and travel to another city, but has not yet decided which city. A travel route to city consists of cities and roads , where:
- ;
- road connects cities and ;
- Sky and Aqua will not pass through the same road twice, so all are distinct. They may pass through the same city multiple times, including the starting city and the ending city .
For each road, Sky computed the video length recorded while traveling on that road. The video length for road is .
During the trip, Sky and Aqua will each choose one road on the route and record a video related to that road. Sky likes short videos, so Sky will choose the road with the smallest ; Aqua likes long videos, so Aqua will choose the road with the largest .
The total length of the two videos is $\min\limits_{1\le i \le q-1}t_{r_{i}} + \max\limits_{1\le i \le q-1}t_{r_{i}}$.
Sky does not want to waste footage, so he wants to stitch the two videos together and publish them on a well-known video website. Since short videos are more popular now, Sky wants to minimize the total length of the two videos as much as possible. To choose the destination and the route, you need to compute, for each destination , among all possible routes from city to city , the minimum possible total length of the two videos.
Input Format
The first line contains two integers and (,), representing the numbers of cities and roads.
The next lines describe the roads. The -th line contains three integers (,,), representing the indices of the cities connected by this road and the video length recorded on this road.
It is guaranteed that, using the existing roads, you can get from any city to any other city.
Output Format
For each , output the minimum possible total length of Sky's and Aqua's videos for a trip from city to city .
3 3
1 2 2
1 3 1
2 3 1
2
2
7 10
1 2 2
1 2 8
2 3 3
3 4 5
3 5 4
4 5 4
6 5 7
6 4 4
1 7 6
6 7 9
4
5
6
6
6
10
4 4
1 2 2
3 2 0
2 4 3
4 3 1
3
2
2
Hint
Constraints are the same as in the input format.
| Subtask | Points | Special Properties | ||
|---|---|---|---|---|
| For all roads connected to city , | ||||
| For all roads connected to city , | ||||
| There is at most one road between each pair of cities | ||||
| For all roads , | ||||
| For all , there is a road between city and ; for any pair of roads and , if and , then 。 | ||||
Translated by ChatGPT 5