Under construction

Still being built. Things may change

Traveling Bloggers

Time limit3sMemory limit1024 MB

Level

Not classified yet

Solved
No attempts yet

Statement

Yan and Tatyana decided to become travel bloggers and post videos about trips around the cities of their country.

The country has nn cities numbered from 1 to nn. City 1 is the capital. The cities are connected by mm two-way roads numbered from 1 to mm, and each road connects two different cities. The same pair of cities may be connected by several roads. From any city, you can reach every other city by road.

The travelers plan to leave the capital for some other city, but they have not chosen which one yet. A route to city kk consists of cities s1,s2,…,sqs_1, s_2, \ldots, s_q and roads r1,r2,…,rq−1r_1, r_2, \ldots, r_{q-1} such that:

  • s1=1s_1 = 1 and sq=ks_q = k.
  • Road rir_i connects cities sis_i and si+1s_{i+1}.
  • They do not drive the same road twice, so all rir_i are distinct. The route may pass through the same city several times, including city 1, where the trip starts, and city kk, where it ends.

For each road ii, the travelers computed the length of the video filmed along it, denoted tit_i.

During the trip, each traveler picks one road of the route and films a video about it. Yan likes short videos, so he picks the road with the smallest tit_i. Tatyana prefers long videos, so she picks the road with the largest tit_i.

The total length of the two videos is min⁡1≤i≤q−1tri+max⁡1≤i≤q−1tri\min\limits_{1 \leq i \leq q-1} t_{r_i} + \max\limits_{1 \leq i \leq q-1} t_{r_i}.

The travelers plan to upload to a platform where short videos are more popular, so they want to minimize the total length of the two videos. For each destination city kk, compute the minimum total length over all routes from city 1 to city kk.

Input

The first line contains two integers nn, mm (2≤n≤300 0002 \leq n \leq 300\,000, 1≤m≤300 0001 \leq m \leq 300\,000), the number of cities and roads.

Each of the next mm lines describes a road. The ii-th of these lines contains three integers uiu_i, viv_i, tit_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n, ui≠viu_i \neq v_i, 0≤ti≤1090 \leq t_i \leq 10^9), the numbers of the two cities the road connects and the video length for that road.

It is guaranteed that you can travel from any city to any other city using the given roads, possibly through other cities.

Output

For each 2≤k≤n2 \leq k \leq n, print the minimum total length of the two travelers' videos for a trip that ends in city kk.

Hint

In the first example, the possible optimal routes are:

  • 1→t=13→t=121 \overset{t = 1}{\to} 3 \overset{t = 1}{\to} 2. The video lengths total 1+1=21 + 1 = 2.
  • 1→t=131 \overset{t = 1}{\to} 3. The video lengths total 1+1=21 + 1 = 2.

In the second example, the possible optimal routes are:

  • 1→t=221 \overset{t = 2}{\to} 2. The video lengths total 2+2=42 + 2 = 4.
  • 1→t=22→t=331 \overset{t = 2}{\to} 2 \overset{t = 3}{\to} 3. The video lengths total 2+3=52 + 3 = 5.
  • 1→t=22→t=33→t=45→t=441 \overset{t = 2}{\to} 2 \overset{t = 3}{\to} 3 \overset{t = 4}{\to} 5 \overset{t = 4}{\to} 4. The video lengths total 2+4=62 + 4 = 6.
  • 1→t=22→t=33→t=451 \overset{t = 2}{\to} 2 \overset{t = 3}{\to} 3 \overset{t = 4}{\to} 5. The video lengths total 2+4=62 + 4 = 6.
  • 1→t=22→t=33→t=45→t=44→t=461 \overset{t = 2}{\to} 2 \overset{t = 3}{\to} 3 \overset{t = 4}{\to} 5 \overset{t = 4}{\to} 4 \overset{t = 4}{\to} 6. The video lengths total 2+4=62 + 4 = 6.
  • 1→t=22→t=81→t=671 \overset{t = 2}{\to} 2 \overset{t = 8}{\to} 1 \overset{t = 6}{\to} 7. The video lengths total 2+8=102 + 8 = 10.

In the third example, the possible optimal routes are:

  • 1→t=22→t=03→t=14→t=321 \overset{t = 2}{\to} 2 \overset{t = 0}{\to} 3 \overset{t = 1}{\to} 4 \overset{t = 3}{\to} 2. The video lengths total 0+3=30 + 3 = 3.
  • 1→t=22→t=031 \overset{t = 2}{\to} 2 \overset{t = 0}{\to} 3. The video lengths total 0+2=20 + 2 = 2.
  • 1→t=22→t=03→t=141 \overset{t = 2}{\to} 2 \overset{t = 0}{\to} 3 \overset{t = 1}{\to} 4. The video lengths total 0+2=20 + 2 = 2.

Examples3

  1. Example 1

    Input
    3 3
    1 2 2
    1 3 1
    2 3 1
    
    Expected output
    2
    2
    
  2. Example 2

    Input
    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
    
    Expected output
    4
    5
    6
    6
    6
    10
    
  3. Example 3

    Input
    4 4
    1 2 2
    3 2 0
    2 4 3
    4 3 1
    
    Expected output
    3
    2
    2