mostovi — COCI CONTEST_#1
Task type: batch | Time limit: 3 s | Memory limit: 512 MB | Difficulty: 24
Algorithms: segment tree, heuristics, dfs

# Task Mostovi

When Leonhard Euler resolved the famous Königsberg bridge problem, he had no clue he had discovered a whole new area of mathematics - graph theory!

Unfortunately, the Königsberg bridge problem is far too easy for the programmers of this era, so Euler came up with another problem - the Zagreb bridge problem!

![](_page_0_Picture_5.jpeg)

The bridges of Zagreb form a graph with $n$ nodes and $m$ edges where the edges represent the bridges and the nodes represent the riverine islands. The graph is connected; in other words, it's possible to get from any node to any other by traveling across the edges. Now Euler asked, how many edges are there such that after their removal the graph becomes disconnected?

Again, Euler didn't know that this problem is also famous today (those damn Codeforces blogs). So the author of this problem decided to give you an even harder one: how many edges are there such that after the removal of the nodes which it connects, the remaining $n - 2$ nodes become disconnected?

## Input

The first line contains integers $n$ and $m$ ($4 \le n \le 100\,000$, $n - 1 \le m \le 300\,000$) - the number of nodes and edges respectively.

Each of the next $m$ lines contains integers $a_i$ and $b_i$ ($1 \le a_i, b_i \le n$) - this means nodes $a_i$ and $b_i$ are connected with an edge.

There are no loops or multiple edges.

## Output

In a single line, output the number of edges with the given property.

## Scoring

| Subtask | Points | Constraints |
|---|---|---|
| 1 | 13 | $n \le 100$, $m \le 300$ |
| 2 | 17 | $n \le 1000$, $m \le 3000$ |
| 3 | 25 | $n \le 1000$ |
| 4 | 12 | $m - n \le 20$ |
| 5 | 43 | No additional constraints. |

![](_page_1_Picture_0.jpeg)

## Examples

| Input | Input |
|---|---|
| 4 5 | 6 7 |
| 1 2 | 1 2 |
| 2 3 | 2 4 |
| 3 4 | 2 6 |
| 4 1 | 3 5 |
| 1 3 | 6 1 |
|  | 4 3 |
|  | 2 5 |
| Output | Output |
| 1 | 4 |

## Clarification of the first example

By removing edge (1, 3) and corresponding nodes 1 and 3, the remaining graph has two connected components, node 2 and node 4. In other words, it is not connected. It is easy to check it is the only edge with this property.

## Clarification of the second example

The edges with the given property are (1, 2), (2, 4), (2, 6) and (2, 5).

Starter code: