PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000102. Những con đường chạy bộ (Jogging Trails)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những con đường chạy bộ (Jogging Trails)

Jogging Trails

Source: LightOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an undirected graph with positive edge weights, find the minimum length of a closed walk covering every edge at least once. The starting vertex may be chosen anywhere within the active component. Output -1 if the graph edges do not all lie in a single connected component.

Input

First n,mn,m, then mm roads u,v,wu,v,w indexed from 11.

Output

Print the minimum tour length, or -1.

Subtasks

  • Subtask 1 (40 points): 1≤n≤61\le n\le 6. All input-format and graph conditions above apply.

  • Subtask 2 (60 points): 1≤n≤131\le n\le 13. All input-format and graph conditions above apply.

Examples

Input

2 1
1 2 3

Output

6

Explanation

The graph has one edge of length 3. A closed walk covering it traverses the edge in both directions, yielding 2×3=62\times3=6.