测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A7844. Traveling Graph

编程题 普及/提高-

题目描述

You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself).

输入格式

The first line of the input contains two integers $n$ and $m$ ( $1<=n<=15,0<=m<=2000$ ), $n$ is the amount of vertices, and $m$ is the amount of edges. Following $m$ lines contain edges as a triples $x,y,w$ ( $1<=x,y<=n,1<=w<=10000$ ), $x,y$ are edge endpoints, and $w$ is the edge length.

输出格式

Output minimal cycle length or -1 if it doesn't exists.

输入输出样例

输入 #1
3 3
1 2 1
2 3 1
3 1 1
输出 #1
3
输入 #2
3 2
1 2 3
2 3 4
输出 #2
14
上一题 去做题 下一题