| 2026 Spring UT CS104c Midterm #1 |
|---|
| Finished |
Magikarp likes to explore Karpville, but sometimes his phone runs out of battery when he is far from home. Karpville is made up of $$$n$$$ intersections and $$$m$$$ one-way streets, the $$$j$$$-th of which goes from intersection $$$u_j$$$ to intersection $$$v_j$$$ and takes $$$w_j$$$ minutes to drive.
Magikarp wonders, if he were to start at intersection $$$i$$$, what is the shortest amount of time (in minutes) it takes to reach his apartment, located at intersection $$$n$$$, if he is only allowed to drive? Help Magikarp answer this question for all intersections.
If Magikarp cannot drive back from some intersection, print $$$-1$$$ for that answer. Note that there can be multiple roads between the same pair of intersections.
Psst... the answers can exceed the size of a 32-bit integer!
The first line of input contains $$$n$$$ and $$$m$$$ $$$(1\le n,m\le 2\cdot 10^5)$$$ — the number of intersections and the number of one-way streets, respectively.
The $$$j$$$-th of the next $$$m$$$ lines contains 3 integers $$$u_j$$$, $$$v_j$$$, and $$$w_j$$$ $$$(1\le u_j,v_j\le n, u_j\neq v_j, 0\le w_j\le 10^9)$$$ — the starting intersection, ending intersection, and distance (in minutes) for the $$$j$$$-th one-way road.
Output $$$n$$$ lines, each containing a single integer. The $$$i$$$-th number should represent the shortest time (in minutes) it will take Magikarp to drive back to his apartment if he starts at intersection $$$i$$$, or $$$-1$$$ if this is impossible.
3 31 2 12 3 21 3 5
3 2 0
6 91 2 12 1 05 2 03 2 44 5 33 4 23 5 75 6 25 6 0
-1 -1 5 3 0 0
| Name |
|---|


