Under construction

Still being built. Things may change

Minions having fun

Time limit2sMemory limit1024 MB

Summary
Given a weighted multigraph, find a closed route that uses each edge at most once and maximizes the sum of its minimum and maximum edge weights.
Level

Hard8 of 10

Topics
Minimum spanning tree, Graph
Solved
No attempts yet

Problem

Gru went shopping with the girls, and the minions are bored with nothing to do. They decided to keep themselves busy with a competition that every minion agreed to join.

The lab map has nn checkpoints. There are mm two-way paths between them, and each path has several bananas on it. A minion starts at any checkpoint, runs along the paths, uses each path at most once, and returns to the starting checkpoint. Suppose a minion ran such a cyclic route and passed through paths with c1,c2,…,ckc_1, c_2, \ldots, c_k bananas. Then the score for that route is min⁡(c1,c2,…,ck)+max⁡(c1,c2,…,ck)\min(c_1, c_2, \ldots, c_k) + \max(c_1, c_2, \ldots, c_k).

The minion Dave wants to win badly. Find the cyclic route with the highest score and help him.

Input

The first line contains two integers nn, mm (1≤n,m≤100 0001 \le n, m \le 100\,000), the number of checkpoints and the number of paths. Each of the next mm lines contains three integers vv, uu, ww (1≤v,u≤n1 \le v, u \le n; v≠uv \ne u; 0≤w≤1090 \le w \le 10^9): the two checkpoints connected by the path and the number of bananas on it. Several paths may connect the same pair of checkpoints.

Output

Print one line with the maximum value of the minimum plus the maximum banana count over all cyclic routes. If no cyclic route exists, print 0.

Hints

In the first sample there is only one cycle, so the answer is the minimum plus the maximum banana count on it: 1+1=21+1=2. In the second sample there is again only one cycle, and the answer is 1+2=31+2=3. In the third sample there are three cycles: 1-2-3-1, 1-2-4-1, and 1-4-2-3-1. The first gives 1+2=31+2=3 points, the second gives 2+2=42+2=4 points, and the third gives 1+2=31+2=3 points. So running the second cycle is best, and the answer is 4. In the fourth sample there is no cycle at all, so the answer is 0.

Examples4

  1. Example 1

    Input
    3 3
    1 2 1
    2 3 1
    3 1 1
    
    Expected output
    2
    
  2. Example 2

    Input
    4 4
    1 2 1
    2 3 2
    3 1 1
    1 4 100
    
    Expected output
    3
    
  3. Example 3

    Input
    4 5
    1 2 2
    2 3 1
    3 1 1
    1 4 2
    4 2 2
    
    Expected output
    4
    
  4. Example 4

    Input
    2 1
    1 2 1
    
    Expected output
    0