General graph matching
Time limit1sMemory limit128 MB
Given an undirected graph with N vertices and M edges, print the size of a maximum matching.
- Level
Hard9 of 10
- Topics
- Graph, Greedy, Backtracking, Implementation
- Solved
- No attempts yet
Problem
A graph with vertices and undirected edges is given. Write a program that prints the size of a maximum matching of that graph.
In a graph (, ), a matching is a subset of in which no two elements share a vertex.
A maximum matching is a matching of the largest possible size.
Input
The first line contains the number of vertices () and the number of edges ().
Each of the next lines describes one edge.
An edge is described by the numbers of the two distinct vertices it joins.
Every vertex number is a natural number between and .
At most one edge joins any given pair of vertices.
Output
Print the size of a maximum matching on the first line.