#P15494. [ICPC 2025 APC] Cactus Connectivity

[ICPC 2025 APC] Cactus Connectivity

Description

You are interested in the topic of graphs and their properties. In this problem, we assume that all graphs are simple undirected graphs, meaning there is at most one edge connecting any pair of vertices and each edge connects different vertices.

A simple cycle of a graph is a sequence of three or more distinct vertices (v1,v2,,vc)(v_1, v_2, \ldots, v_c) such that there exists an edge connecting vertices viv_i and vi+1v_{i+1} for each 1i<c1 \leq i < c and there also exists an edge connecting vertices v1v_1 and vcv_c. For a simple cycle (v1,v2,,vc)(v_1, v_2, \ldots, v_c), its edge set is defined as $\{(v_1, v_2), (v_2, v_3), \ldots, (v_{c-1}, v_c), (v_c, v_1)\}$, where (vi,vj)(v_i, v_j) represents an edge connecting vertices viv_i and vjv_j. Two simple cycles are the same if they share the same edge set.

A graph is a cactus if any two distinct simple cycles share at most one common vertex. For example, Figure C.1 illustrates three graphs. Graph XX is a cactus since the two simple cycles (1,2,3)(1, 2, 3) and (3,4,5)(3, 4, 5) only share vertex 33 as the common vertex. Note that the sequence of vertices (1,2,3,4,5,3)(1, 2, 3, 4, 5, 3) does not form a simple cycle since vertex 33 appears twice. Also, the simple cycle (2,3,1)(2, 3, 1) is the same simple cycle as the simple cycle (1,2,3)(1, 2, 3). Meanwhile, graph YY is not a cactus since the two simple cycles (1,2,4)(1, 2, 4) and (2,3,4)(2, 3, 4) share vertices 22 and 44 as the common vertices. Graph ZZ is a cactus since there is only one simple cycle.

:::align{center}

Figure C.1: Graphs XX and ZZ are cactii. Graph YY is not a cactus. :::

A graph is connected if there is a path connecting every pair of vertices. In particular, a graph with one vertex is connected.

For any positive integer kk, a graph is kk-edge-connected if, for any set of fewer than kk edges, removing those edges leaves the graph connected. In particular, all connected graphs are 11-edge-connected. For example, graph YY in Figure C.1 is 11-edge-connected and 22-edge-connected, but not 33-edge-connected, since removing both edges incident to vertex 11 does not leave the graph connected.

A graph HH is a supergraph of a graph GG if HH can be obtained by adding zero or more vertices and edges to GG without removing any vertices and edges from GG. Note that two graphs are the same if they have the same set of vertices and the same set of edges. For example, in Figure C.1 above, graph XX is a supergraph of graph ZZ, while graph YY is not a supergraph of graph ZZ since it is missing the edge connecting vertices 11 and 33.

The connectivity value of a graph GG is the smallest positive integer kk such that, for any kk-edge-connected graph HH that is a supergraph of GG, removing all the edges of GG from HH keeps HH connected. For example, in Figure C.1 above, graph XX is a 22-edge-connected supergraph of graph ZZ, and removing all the edges of ZZ from XX leaves vertices 11 and 22 disconnected from the rest, as illustrated by Figure C.2 below. Therefore, the connectivity value of ZZ is more than 22. It can be shown that the connectivity value of ZZ is 33.

:::align{center}

Figure C.2: Removing the edges of graph ZZ from graph XX :::

You are given a cactus with nn vertices and mm edges, where the vertices are numbered from 11 to nn and the edges are 11 to mm. Edge ii connects vertices uiu_i and viv_i. You are required to compute the connectivity value of the cactus.

Input Format

The first line of input contains two integers nn and mm (1n1000001 \leq n \leq 100\,000; 0m2000000 \leq m \leq 200\,000). The ii-th of the next mm lines contains two integers uiu_i and viv_i (1ui<vin1 \leq u_i < v_i \leq n). The input represents a cactus with at most one edge connecting any pair of vertices.

Output Format

Output the connectivity value of the given graph.

4 3
1 2
2 3
1 3
3
3 0
1

Hint

Explanation for the sample input/output #1

This corresponds to graph ZZ from the problem description.

Explanation for the sample input/output #2

Any 11-edge-connected supergraph is a connected graph. Since the given graph has no edges, removing all the edges of the given graph from a connected graph keeps the graph connected.