#abc288c. C - Don’t be cycle

C - Don’t be cycle

Score : 300300 points

问题陈述

给定一个包含 NN 个顶点和 MM 条边的简单无向图。顶点编号为 11NN,第 ii 条边连接顶点 AiA_i 和顶点 BiB_i。我们需要删除零个或多个边以去除图中的环路。请找出为了达到此目的必须删除的最少边数。

什么是简单无向图?简单无向图是一种没有自环和平行边、且边无方向的图。

什么是环路?在简单无向图中,环路是指长度至少为 33 的顶点序列 (v0,v1,,vn1)(v_0, v_1, \ldots, v_{n-1}),满足当 iji \neq j 时有 vivjv_i \neq v_j,并且对于每个 0i<n0 \leq i < n,存在一条连接顶点 viv_iv(i+1)modnv_{(i+1) \bmod n} 的边。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a simple undirected graph with NN vertices and MM edges. The vertices are numbered 11 to NN, and the ii-th edge connects vertex AiA_i and vertex BiB_i. Let us delete zero or more edges to remove cycles from the graph. Find the minimum number of edges that must be deleted for this purpose.

What is a simple undirected graph? A simple undirected graph is a graph without self-loops or multi-edges whose edges have no direction.

What is a cycle? A cycle in a simple undirected graph is a sequence of vertices (v0,v1,,vn1)(v_0, v_1, \ldots, v_{n-1}) of length at least 33 satisfying vivjv_i \neq v_j if iji \neq j such that for each 0i<n0 \leq i < n, there is an edge between viv_i and vi+1modnv_{i+1 \bmod n}.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0M2×1050 \leq M \leq 2 \times 10^5
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • The given graph is simple.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

AMA_M BMB_M

Output

Print the answer.

Sample Input 1

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

Sample Output 1

2

One way to remove cycles from the graph is to delete the two edges between vertex 11 and vertex 22 and between vertex 44 and vertex 55.
There is no way to remove cycles from the graph by deleting one or fewer edges, so you should print 22.

Sample Input 2

4 2
1 2
3 4

Sample Output 2

0

Sample Input 3

5 3
1 2
1 3
2 3

Sample Output 3

1

update @ 2024/3/10 12:01:52