#P17166. [CEOI 2026] Flower Cutting

[CEOI 2026] Flower Cutting

Problem Description

In the CEOI community garden, we are growing a collection of special flowers that tightly knit their roots together. If we cut them, they regrow, as long as we do not cut too aggressively and cause irreparable damage.

If a pair of flowers, aa and bb, knit their roots together, we call them "connected". Otherwise, they are "disconnected". Roots grow according to the following rule: Let aa and bb be two disconnected flowers. If at least 22 other flowers cc and dd exist, such that each of aa and bb is connected with both cc and dd, then roots between aa and bb will grow, and they will become connected.

These flowers have now been growing for a while, and all the roots that could grow by following the above rule have grown. In other words, if two flowers aa and bb are both connected with some flowers cc and dd, then aa and bb are guaranteed to be connected with each other.

We need to uproot this garden and move it to the next CEOI location. To simplify the migration, we would like to cut as many roots as possible. However, we want the flowers to regrow back into their current state. What is the maximum number of connected pairs of flowers that we may cut so that they still regrow back into their current state? It does not matter how many iterations of growth it would take.

Input Format

The first line of the input contains two space-separated integers nn and mm, the number of flowers and the number of existing connections between them. This is followed by mm lines, each containing a pair of integers aia_i and bib_i, indicating that flowers aia_i and bib_i are connected. Flowers are marked with integers 1n1\ldots n. The input is guaranteed to follow the rule described in the task description.

Output Format

Output a single integer - the maximum number of connections that we may cut.

9 14
1 2
1 4
1 5
2 4
2 5
3 4
4 5
3 6
4 6
6 7
6 9
7 9
8 9
5 8
2

Hint

Comment

The flowers in the example before any cutting. One can check that no additional connections can form based on the described growth procedure.

:::align{center} :::

The flowers in the example after the cutting have 22 connections less. The connection between 11 and 22 can regrow because flowers 11 and 22 are both connected to flowers 44 and 55. Similarly, the connection between 44 and 55 can regrow because flowers 44 and 55 are both connected to flowers 11 and 22.

:::align{center} :::

Constraints

  • 1n10001\le n\le 1000
  • 1m1051\le m\le 10^5

Subtasks

  • Subtask 11 (2020 points): n10n\le 10 and m20m\le 20
  • Subtask 22 (1414 points): m=n(n1)2m=\dfrac{n(n-1)}{2}
  • Subtask 33 (1515 points): We guarantee that each flower is connected with at most 77 other flowers.
  • Subtask 44 (1515 points): n50n\le 50 and m1000m\le 1000
  • Subtask 55 (3636 points): No additional constraints.