Floor is Lava
시간 제한2초메모리 제한2048 MB
각 방에서 부츠의 냉각 단계를 조절할 수 있고 간선 온도 c를 지날 때 |현재 단계 - c|의 비용이 들 때, 방 1에서 방 N까지 가는 최소 비용을 구한다.
문제
You’re trapped in a scorching dungeon with rooms numbered from 1to connected by tunnels. The i$$-th tunnel connects rooms and in both directions, but the floor of the tunnel is covered in lava with temperature .
To help you navigate the lavatic tunnels, you are wearing a pair of heat-resistant boots that initially have a chilling level of . In order to step through lava with temperature , your boots must have the same chilling level ; 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 for a cost of coins. You start in room and would like to reach the exit which you know is located in room . What is the minimum cost to do so?
입력
The first line of input contains two integers and ().
The next lines each contain three integers , , and (, , ), describing the -th tunnel.
There is at most one tunnel connecting any pair of rooms, and it is possible to reach all other rooms from room .
출력
Output the minimum cost (in coins) to reach room from room .