Cheapest cycle P18546


Statement
 

pdf   zip

You are given an undirected graph with positive costs at the edges. Please compute the cheapest cycle of the graph.

Input

Input consists of several cases, each with the number of vertices nn, followed by the number of edges mm, followed by mm triples xx yy cc to indicate an edge connecting xx and yy with cost cc, where xyx \ne y and 1c1061 \le c \le 10^6. Vertices are numbered starting from 0. For every pair of vertices, there is at most one edge connecting them. Assume 3n10003 \le n \le 1000 and nm5nn \le m \le 5n.

Output

For every case, print the cost of the cheapest cycle of the graph.

Public test cases
  • Input

    3 3
    0 1 10  0 2 20  1 2  30
    7 8
    5 0 70  4 5 10  0 4 40  2 1 40  3 6 1  5 2 30  4 1 30  4 2 80
    

    Output

    60
    110
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++