Hamiltonian Path
题号:NC52814
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
Special Judge, 64bit IO Format: %lld

题目描述

In ICPCCamp, there are n cities and m directed roads between cities.
The i-th road going from the a_i-th city to the b_i-th city is c_i kilometers long.
For each pair of cities (u, v), there can be more than one roads from u to v.
Bobo wants to make big news by solving the famous *Hamiltonian Path* problem.
That is, he would like to visit all the n cities one by one so that the total distance travelled is minimized.
Formally, Bobo likes to find n **distinct** integers
to minimize where w(x, y) is the length of road from the x-th city to the y-th city.

输入描述:

The input contains at most 30 sets. For each set:
The first line contains 2 integers n, m ().
The i-th of the following m lines contains 3 integers a_i, b_i, c_i
().

输出描述:

For each set, an integer denotes the minimum total distance.
If there exists no plan, output `-1` instead.
示例1

输入

复制
3 3
1 2 1
1 3 1
2 3 1

输出

复制
2
示例2

输入

复制
3 2
1 2 1
1 3 2

输出

复制
-1