Just Dijkstra P30288


Statement
 

pdf   zip

Write a program to compute the minimum cost to go from one vertex to each of the vertices of a given directed graph with positive costs at the arcs.

Input

Input consists of several cases. Every case begins with the number of vertices nn and the number of arcs mm, followed by mm triples xx yy cc, to indicate an arc from xx to yy with cost cc. Assume 2n1042 \le n \le 10^4, 0m5n0 \le m \le 5n, that vertices are numbered from 0 to n1n - 1, xyx \ne y, that for every pair xx yy there is at most one arc in each direction, and that all costs cc are natural numbers between 1 and 10410^4.

Output

For every case, print the minimum cost to go from vertex 0 to the rest of vertices, in order from 1 to n1n - 1. If there is no path to some vertex, print “no”. Print a line with 10 dashes at the end of every case.

Public test cases
  • Input

    4 3
    0 1 100
    0 3 200
    1 3 50
    
    2 1
    1 0 10000
    

    Output

    100
    no
    150
    ----------
    no
    ----------
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++