Logo
(追記) (追記ここまで)

34469번 - Floor is Lava 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB32161062.500%

문제

You’re trapped in a scorching dungeon with $N$ rooms numbered from 1$ $to $N$ connected by $M$ tunnels. The i$$-th tunnel connects rooms $a_i$ and $b_i$ in both directions, but the floor of the tunnel is covered in lava with temperature $c_i$.

To help you navigate the lavatic tunnels, you are wearing a pair of heat-resistant boots that initially have a chilling level of 0ドル$. 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 $d$ for a cost of $d$ coins. You start in room 1ドル$ and would like to reach the exit which you know is located in room $N$. What is the minimum cost to do so?

입력

The first line of input contains two integers $N$ and $M$ (1ドル ≤ N, M ≤ 200,円 000$).

The next $M$ lines each contain three integers $a_i,ドル $b_i,ドル and $c_i$ (1ドル ≤ a_i , b_i ≤ N,ドル $a_i \ne b_i ,ドル 1ドル ≤ c_i ≤ 10^9$), describing the $i$-th tunnel.

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

출력

Output the minimum cost (in coins) to reach room $N$ from room 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

예제 출력 1

9

A diagram of the dungeon is shown above. The optimal escape strategy is as follows:

  1. Increase the chilling level to 3ドル$ for a cost of 3ドル$ coins.
  2. Walk through the tunnel to room 2ドル.$
  3. Decrease the chilling level to 2$$ for a cost of 1ドル$ coin.
  4. Walk through the tunnel to room 3ドル$.
  5. Increase the chilling level to 3ドル$ for a cost of 1ドル$ coin.
  6. Walk through the tunnel to room 4ドル$.
  7. Increase the chilling level to 7ドル$ for a cost of 4ドル$ coins.
  8. Walk through the tunnel to room 5ドル$ and escape.

This has a total cost of 9ドル$ coins, and it can be shown that no cheaper route exists.

노트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2025 > CCC 2025 Senior Division 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /