Maximum Weight Matching in a General Graph

Given a weighted undirected graph, find a matching with maximum total edge weight.

Hard9GraphGreedyDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a weighted undirected graph with NN vertices and MM edges. Write a program that prints the total weight of a maximum weight matching of that graph.

In a graph G=(V,E)G = (V, E), a matching TT is a subset of EE in which no two edges share a vertex. A maximum weight matching is a matching whose edge weights add up to the largest total. The empty set, which takes no edge at all, is also a matching.

Input

The first line contains the number of vertices NN (1N4001 \le N \le 400) and the number of edges MM (1MN(N1)/21 \le M \le N(N-1)/2).

Each of the next MM lines holds the information of one edge: the numbers of the two distinct vertices it joins, and its weight.

A vertex number is a natural number between 1 and NN, and an edge weight is a natural number between 1 and 500,000,000. There is at most one edge between any two vertices.

Output

Print the total weight of a maximum weight matching on the first line.