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

#FW0000101. Đồ thị du hành (Traveling Graph)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đồ thị du hành (Traveling Graph)

Traveling Graph

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a weighted undirected multigraph, possibly with parallel edges and self-loops, find the minimum length of a closed walk starting at vertex 1, traversing every edge at least once, and returning to vertex 1. Output -1 if no such walk exists. All original edge weights must contribute, including parallel edges.

Input

First n,mn,m, followed by mm edges u,v,wu,v,w, with 1-based indices.

Output

Print the minimum total 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

To start and finish at vertex 1 while covering the only edge, the walk must be 1→2→11\to2\to1. Both traversals cost 3, totaling 3+3=63+3=6.