Cactus Connectivity

시간 제한2초메모리 제한2048 MB

요약
선인장 그래프가 주어질 때, G의 간선을 모두 지워도 연결성을 유지하게 하는 k-간선연결 상위 그래프가 존재하는 최소 k인 연결성 값을 구한다.
난이도

어려움10점 중 9점

유형
그래프, DFS, 그리디, 구현
정답자
아직 제출이 없습니다

문제

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 (v_1,v_2,…,v_c)(v\_1, v\_2, \dots , v\_c) such that there exists an edge connecting vertices v_iv\_i and v_i+1v\_{i+1} for each 1≤i<c1 ≤ i < c and there also exists an edge connecting vertices v_1v\_1 and v_cv\_c. For a simple cycle (v_1,v_2,…,v_c)(v\_1, v\_2, \dots , v\_c), its edge set is defined as (v_1,v_2),(v_2,v_3),…,(v_c−1,v_c),(v_c,v_1)\\{(v\_1, v\_2),(v\_2, v\_3), \dots ,(v\_{c−1}, v\_c),(v\_c, v\_1)\\}, where (v_i,v_j)(v\_i , v\_j ) represents an edge connecting vertices v_iv\_i and v_jv\_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.

Graph XXGraph YYGraph ZZ

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.

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 u_iu\_i and v_iv\_i. You are required to compute the connectivity value of the cactus.

입력

The first line of input contains two integers nn and mm (1≤n≤100,0001 ≤ n ≤ 100\\, 000; 0≤m≤200,0000 ≤ m ≤ 200\\, 000). The ii-th of the next mm lines contains two integers u_iu\_i and v_iv\_i (1≤u_i<v_i≤n1 ≤ u\_i < v\_i ≤ n). The input represents a cactus with at most one edge connecting any pair of vertices.

출력

Output the connectivity value of the given graph.

예제2

  1. 예제 1

    입력
    4 3
    1 2
    2 3
    1 3
    
    예상 출력
    3
    
  2. 예제 2

    입력
    3 0
    
    예상 출력
    1