Dijkstra?

Write a program that, given a directed multigraph with arcs with
positive costs, computes the cost of the second cheapest walk from
vertex 0 to every other vertex. Remember that a multigraph may have arcs
from x to x, and more than one arc from x to y. Also remember that a
walk can repeat vertices and arcs.

Input

Input consists of several cases. Every case begins with the number of
vertices n and the number of arcs m, followed by m triples x y c to
indicate an arc from x to y with cost c. Assume 2 ≤ n ≤ 10⁴, 0 ≤ m ≤ 5n,
that vertices are numbered from 0 to n − 1, and that every cost c is an
integer number between 1 and 10⁴.

Output

For every case, print the second minimum cost of walking from 0 to the
rest of vertices, ordered from 1 to n − 1. If there is no second best
walk to some vertex, just print “no”. Print a line with ten dashes at
the end of every case.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:30:16.978Z

© Jutge.org, 2006–2026.
https://jutge.org
