Cheapest cycle

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 x≠yx \ne y and 1≤c≤1061 \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 3≤n≤10003 \le n \le 1000 and n≤m≤5nn \le m \le 5n.

Output

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

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:20:57.846Z

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