This page is still under construction.

Parts of this page are still being built. What you see may change.

Heracles

Time limit2sMemory limit64 MB

Summary
Find the shortest closed walk from city 1 that visits each of the 12 required cities at least once and returns to city 1, in a weighted undirected graph.
Level

Medium6 of 10

Topics
Graph, Shortest path, Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

In Ancient Greece there are nn cities connected by mm bidirectional roads. It is possible to reach any city from any other by moving along the roads. There is at most one road between any two cities, and each road connects two distinct cities. Road ii has length cic_i.

Heracles urgently has to perform 1212 labours as directed by King Eurystheus. The labours must be performed in 1212 certain cities of Ancient Greece. Heracles is currently in the city of Mycenae, which is not among these 1212 cities. To finish the labours as fast as possible, Heracles wants to devise an optimal travel plan, according to which he must visit the 1212 required cities and return to Mycenae in the least possible time.

Help Heracles determine the minimum time for the travel. Heracles traverses a road of length cic_i in time cic_i. Every road can be traversed any number of times in either direction, and any city can be visited any number of times. The order of visiting the cities does not matter. Time spent performing the labours does not need to be counted.

Input

The first line contains the integers nn and mm (13≤n≤10513 \le n \le 10^5, n−1≤m≤min⁡(n(n−1)2,105)n-1 \le m \le \min(\frac{n(n-1)}{2}, 10^5)).

The following mm lines describe the roads. The ii-th of them has the form <<aia_i bib_i cic_i>>, meaning that the ii-th road connects the cities numbered aia_i and bib_i and has length cic_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i, 1≤ci≤10001 \le c_i \le 1000). It is guaranteed that there is at most one road between any two cities, and that it is possible to reach every city from any other city.

Mycenae has number 11, and the cities where Heracles must perform the labours have numbers from 22 to 1313.

Output

Output one integer: the minimum possible time of the travel.

Hint

One of the optimal travel plans for the sample is 1→2→3→4→3→2→1→14→5→8→7→1 \to \mathbf{2} \to \mathbf{3} \to \mathbf{4} \to 3 \to 2 \to 1 \to 14 \to \mathbf{5} \to \mathbf{8} \to \mathbf{7} \to →6→9→10→11→10→15→12→13→14→1.\to \mathbf{6} \to \mathbf{9} \to \mathbf{10} \to \mathbf{11} \to 10 \to 15 \to \mathbf{12} \to \mathbf{13} \to 14 \to 1.

Examples1

  1. Example 1

    Input
    15 20
    1 2 5
    2 3 6
    3 4 7
    1 14 10
    14 5 3
    5 6 10
    5 7 20
    5 8 2
    6 7 2
    6 8 20
    7 8 5
    6 9 5
    9 11 20
    10 9 5
    10 11 5
    10 15 7
    15 12 6
    12 13 8
    13 14 9
    15 4 1000
    
    Expected output
    118