CCC '25 S4 - Floor is Lava
View as PDFCanadian Computing Competition: 2025 Stage 1, Senior #4
You're trapped in a scorching dungeon with rooms numbered from
to
connected by
tunnels. The
-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?
Input Specification
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 .
The following table shows how the available marks are distributed:
| Marks | Additional constraints |
|---|---|
| 2 | |
| 4 | For all tunnels, |
| 4 | Each room has at most |
| 5 | None |
Output Specification
Output the minimum cost (in coins) to reach room from room
.
Sample Input
5 7
1 2 3
2 3 2
1 3 6
3 4 3
4 5 7
2 4 1
2 5 10
Sample Output
9
Explanation for Sample Output
A diagram of the dungeon is shown above. The optimal escape strategy is as follows:
- Increase the chilling level to
for a cost of
coins.
- Walk through the tunnel to room
.
- Decrease the chilling level to
for a cost of
coin.
- Walk through the tunnel to room
.
- Increase the chilling level to
for a cost of
coin.
- Walk through the tunnel to room
.
- Increase the chilling level to
for a cost of
coins.
- Walk through the tunnel to room
and escape.
This has a total cost of coins, and it can be shown that no cheaper route exists.
Comments
do you pronounce "dijkstra's" as "jikstras" or "dikstras"
I think the seccond one. bruce pronounces it that way so it must be.
Edit: This is what google says.
If u dont understand like me, search up Dijkstra's Algorithm.
Somehow, my algorithm is fast enough for Batch 3 but not Batch 1 (Case 10) 🤔
Is this an issue with DMOJ itself? Case 9 and 10 for Batch 1 seem to take equivalent amounts of time when running the test data on my own machine, but Case 10 always gives TLE when submitting here (both with Python 3 or PyPy3). Edit: nvm, the test data seems to start at 02 for Case 1. I was comparing the wrong data
reason for batch 3 passing: