#P11095. [ROI 2021] 旅行 (Day 2)

    ID: 10706 远端评测题 1000~3000ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2021Special JudgeROI(俄罗斯)

[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 nn cities, numbered from 11 to nn. City 11 is the capital. There are mm undirected roads between the cities, numbered from 11 to mm, 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 kk consists of cities s1,s2,,sqs_1, s_2,\dots,s_q and roads r1,r2,,rq1r_1,r_2,\dots,r_{q-1}, where:

  • s1=1,sq=ks_1 = 1,s_q = k;
  • road rir_i connects cities sis_i and si+1s_{i+1};
  • Sky and Aqua will not pass through the same road twice, so all rir_i are distinct. They may pass through the same city multiple times, including the starting city 11 and the ending city kk.

For each road, Sky computed the video length recorded while traveling on that road. The video length for road ii is tit_i.

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 tit_i; Aqua likes long videos, so Aqua will choose the road with the largest tit_i.

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 kk, among all possible routes from city 11 to city kk, the minimum possible total length of the two videos.

Input Format

The first line contains two integers nn and mm (2n3000002 \le n \le 3000001m3000001 \le m \le 300000), representing the numbers of cities and roads.

The next mm lines describe the roads. The ii-th line contains three integers ui,vi,tiu_i,v_i,t_i (1ui,vin1 \le u_i,v_i \le nuiviu_i \ne v_i0ti1090 \le t_i \le 10^9), 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 2kn2 \le k \le n, output the minimum possible total length of Sky's and Aqua's videos for a trip from city 11 to city kk.

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 nn\le mm\le Special Properties
11 99 300000300000 m=n1m=n-1
22 1717 For all roads ii connected to city 11, ti=0t_i=0
33 1212 For all roads ii connected to city 11, ti=109t_i=10^9
44 99 1010 There is at most one road between each pair of cities
55 66 2020
66 20002000 For all roads ii, uivi=1\lvert u_i-v_i\rvert=1
77 99
88 50005000 300000300000
99 1010 300000300000 For all aa, there is a road between city aa and a+1a + 1; for any pair of roads ii and jj, if uivi=1\lvert u_i − v_i\rvert = 1 and ujvj>1\lvert u_j − v_j\rvert > 1, then titjt_i \le t_j
1010 1414

Translated by ChatGPT 5