#P9907. [COCI 2023/2024 #1] Mostovi

[COCI 2023/2024 #1] Mostovi

Background

Abusing the judging system for this problem will result in an account ban.

Problem Description

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 programmers nowadays, so Euler came up with another problem: the Zagreb bridge problem.

The bridges of Zagreb form a graph with nn nodes and mm edges, where the edges represent the bridges and the nodes represent the river islands. The graph is connected; in other words, it is possible to get from any node to any other by traveling along the edges. Now Euler asked: how many edges are there such that after removing them, the graph becomes disconnected?

Again, Euler did not know that this problem is also well known 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 removing the two nodes it connects, the remaining n2n - 2 nodes become disconnected?

Main idea

Given a connected undirected graph with nn nodes and mm edges, find how many edges satisfy that after deleting the two endpoints of this edge, the remaining n2n - 2 nodes are disconnected.

Input Format

The first line contains two positive integers n,mn, m, representing the number of nodes and edges.

Each of the next mm lines contains two positive integers ai,bia_i, b_i, meaning there is an edge connecting aia_i and bib_i.

Output Format

Output one integer, the number of edges that satisfy the condition.

4 5
1 2
2 3
3 4
4 1
1 3
1
6 7
1 2
2 4
2 6
3 5
6 1
4 3
2 5
4

Hint

Sample Explanation #1

For the edge (1,3)(1, 3), after deleting it and the corresponding nodes 1,31, 3, there are two connected components, containing nodes 22 and 44 respectively. That is, the graph becomes disconnected. It is easy to verify that this is the only edge that satisfies the condition.

Sample Explanation #2

The edges that satisfy the condition are: (1,2),(2,4),(2,6),(2,5)(1, 2), (2, 4), (2, 6), (2, 5).

Constraints

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1m3×1051 \leq m \leq 3 \times 10^5, 1ai,bin1 \leq a_i, b_i \leq n. There are no multiple edges or self-loops in the graph.

This problem uses bundled tests.

Subtask Special Property Score
11 n100n \leq 100, m300m \leq 300 1313
22 n1000n \leq 1000, m3000m \leq 3000 1717
33 n1000n \leq 1000 2525
44 mn20m - n \leq 20 1212
55 No special property 4343

Notes

The score of this problem follows the original COCI setting, with a full score of 110110.

Translated from COCI2023-2024 CONTEST #1 T5 Mostovi

Translated by ChatGPT 5