Floor is Lava

시간 제한2초메모리 제한2048 MB

요약
각 방에서 부츠의 냉각 단계를 조절할 수 있고 간선 온도 c를 지날 때 |현재 단계 - c|의 비용이 들 때, 방 1에서 방 N까지 가는 최소 비용을 구한다.
난이도

보통10점 중 7점

유형
그래프, 최단 경로, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

You’re trapped in a scorching dungeon with NN rooms numbered from 1 to NN connected by MM tunnels. The i$$-th tunnel connects rooms a_ia\_i and b_ib\_i in both directions, but the floor of the tunnel is covered in lava with temperature c_ic\_i.

To help you navigate the lavatic tunnels, you are wearing a pair of heat-resistant boots that initially have a chilling level of 00. In order to step through lava with temperature ℓ\ell, your boots must have the same chilling level ℓ\ell; if the chilling level is too low then the lava will melt your boots, and if it’s too high then your feet will freeze as you cross the tunnel.

Luckily, when you’re standing in a room, you can increase or decrease the chilling level of your boots by dd for a cost of dd coins. You start in room 11 and would like to reach the exit which you know is located in room NN. What is the minimum cost to do so?

입력

The first line of input contains two integers NN and MM (1≤N,M≤200,0001 ≤ N, M ≤ 200\\, 000).

The next MM lines each contain three integers a_ia\_i, b_ib\_i, and c_ic\_i (1≤a_i,b_i≤N1 ≤ a\_i , b\_i ≤ N, a_i≠b_ia\_i \ne b\_i , 1≤c_i≤1091 ≤ c\_i ≤ 10^9), describing the ii-th tunnel.

There is at most one tunnel connecting any pair of rooms, and it is possible to reach all other rooms from room 11.

출력

Output the minimum cost (in coins) to reach room NN from room 11.

예제1

  1. 예제 1

    입력
    5 7
    1 2 3
    2 3 2
    1 3 6
    3 4 3
    4 5 7
    2 4 1
    2 5 10
    
    예상 출력
    9