Maximum Weight Matching in a General Graph
Time limit2sMemory limit512 MB
Given a weighted undirected graph, find a matching with maximum total edge weight.
- Level
Hard9 of 10
- Topics
- Graph, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a weighted undirected graph with vertices and edges. Write a program that prints the total weight of a maximum weight matching of that graph.
In a graph , a matching is a subset of 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 () and the number of edges ().
Each of the next 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 , 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.