RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
R03618

S4. Floor is Lava

Unrated 레이팅 미적용
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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?

제약

\((1 \le N, M \le 200\,000)\)
\((1 \le a_i, b_i \le N, a_i \neq b_i, 1 \le c_i \le 10^9)\)

입력 형식

The first line of input contains two integers \(N\) and \(M\) \((1 \le N, M \le 200\,000)\).

The next \(M\) lines each contain
three integers \(a_i\), \(b_i\), and \(c_i\) \((1 \le a_i, b_i \le N, a_i \neq b_i, 1 \le c_i \le 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

13점

\(M=N-1\)

2

27점

For all tunnels, \(1 \le c_i \le 10\)

3

26점

Each room has at most 5 outgoing tunnels

4

34점

None

예제 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
설명

A diagram of the dungeon is shown below.

The optimal escape strategy is as follows:

  • Increase the chilling level to \(3\) for a cost of \(3\) coins.

  • Walk through the tunnel to room \(2\).

  • Decrease the chilling level to \(2\) for a cost of \(1\) coin.

  • Walk through the tunnel to room \(3\).

  • Increase the chilling level to \(3\) for a cost of \(1\) coin.

  • Walk through the tunnel to room \(4\).

  • Increase the chilling level to \(7\) for a cost of \(4\) coins.

  • 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.

문제 정보

생성자가 기록되지 않았습니다.

출처 CCC 2025 Senior

평가 및 의견

S4. Floor is Lava

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

S4. Floor is Lava

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8