Under construction

Still being built. Things may change

General graph matching

Time limit1sMemory limit128 MB

Summary
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 NN vertices and MM undirected edges is given. Write a program that prints the size of a maximum matching of that graph.

In a graph G=(V,E)G = (V, E) (∣V∣=N|V| = N, ∣E∣=M|E| = M), a matching TT is a subset of EE 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 NN (1≤N≤5001 \le N \le 500) and the number of edges MM (1≤M≤1247501 \le M \le 124750).

Each of the next MM 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 11 and NN.

At most one edge joins any given pair of vertices.

Output

Print the size of a maximum matching on the first line.

Examples2

  1. Example 1

    Input
    10 20
    9 2
    7 6
    10 8
    3 9
    1 10
    7 1
    10 9
    8 6
    8 2
    8 1
    3 1
    7 5
    4 7
    5 9
    7 8
    10 4
    9 1
    4 8
    6 3
    2 5
    
    Expected output
    5
    
  2. Example 2

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