Under construction

Still being built. Things may change

Rings and Strings

Time limit10sMemory limit512 MB

Summary
Given N rings and the black strings between them, choose a subset of rings to hang so that the number of black strings between hung and unhung rings is maximized.
Level

Hard8 of 10

Topics
Dynamic programming, Graph, Tree
Solved
No attempts yet

Problem

Misawa, an artist, is trying to make a new work. Misawa prepared a large number of metal rings and black and white strings of two colors.

Misawa can make a work by repeatedly tying two different rings together with a string of either color. A ring may be tied to several rings, but each pair of rings is joined by at most one string.

Misawa wants to make a good work, since it takes effort to make one. A 'good work' is defined as follows.

  • A single ring is a good work.
  • Given two good works, connecting every pair of rings that are not joined by a string in either work with a white string gives one good work. (Figure 1. Operation 1)
  • Swapping every white string with a black string and every black string with a white string in a good work gives a good work. (Figure 1. Operation 2)
  • Only the objects defined above are good works.

Figure 1 is an example of a good work.

Figure 1. Example of a good work

Misawa finished a good work that satisfies these conditions. Misawa will select zero or more rings in this work, hang them from the ceiling, and display them. Misawa wants the black strings to stand out as much as possible. In other words, Misawa wants to maximize the number of black strings connecting a ring hanging from the ceiling with a ring that is not hanging.

Find the maximum number of black strings connecting a ring hanging from the ceiling with a ring that is not hanging, when displayed this way.

Input

The input is given in the following format.

NN MM

u1u_1 v1v_1

...

uMu_M vMv_M

NN (1≤N≤50001 \leq N \leq 5000) is the number of rings in the work. MM (1≤M≤1000001 \leq M \leq 100000) is the number of black strings in the work.

uiu_i and viv_i (1≤ui,vi≤N1 \leq u_i, v_i \leq N) mean that the ii-th black string connects ring uiu_i and ring viv_i. Any pair of rings not given in the input is connected by a white string.

The work given in the input is guaranteed to be a good work.

Output

Print the maximum number of black strings connecting a ring hanging from the ceiling with a ring that is not hanging.

Examples3

  1. Example 1

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

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

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