아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Graph Theory

시간 제한1초메모리 제한1024 MB

요약
사이클 그래프에서 간선 하나를 제거해 주어진 질의 쌍들의 최단 경로 거리 최댓값을 최소화한다.
난이도

보통10점 중 6점

유형
그래프, 이분 탐색, 최단 경로, 투 포인터
정답자
아직 제출이 없습니다

문제

Bobo has an undirected graph GG with nn vertices labeled by 1,…,n1, \dots, n and nn edges. For each 1≤i≤n1 \leq i \leq n, there is an edge between the vertex ii and the vertex (i mod n)+1(i \bmod n) + 1. He also has a list of mm pairs (a_1,b_1),…,(a_m,b_m)(a\_1, b\_1), \dots, (a\_m, b\_m).

Now, Bobo is going to choose an ii and remove the edge between the vertex ii and the vertex (i mod n)+1(i \bmod n) + 1. Let δ_i(u,v)\delta\_i(u, v) be the number of edges on the shortest path between the uu-th and the vv-th vertex after the removal. Choose an ii to minimize the maximum among δ_i(a_1,b_1),…,δ_i(a_m,b_m)\delta\_i(a\_1, b\_1), \dots, \delta\_i(a\_m, b\_m).

Formally, find the value of \min\_{1 \leq i \leq n}\left\\{\max\_{1 \leq j \leq m} \delta\_i(a\_j, b\_j)\right\\}\text{.}

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains two integers nn and mm.

For the following mm lines, the ii-th line contains two integers a_ia\_i and b_ib\_i.

출력

For each test case, output an integer which denotes the minimum value.

제한

  • 2≤n≤2×1052 \leq n \leq 2 \times 10^5
  • 1≤m≤2×1051 \leq m \leq 2 \times 10^5
  • 1≤a_i,b_i≤n1 \leq a\_i, b\_i \leq n for each 1≤i≤m1 \leq i \leq m
  • In each input, the sum of nn does not exeed 2×1052 \times 10^5. The sum of mm does not exceed 2×1052 \times 10^5.

힌트

For the first case,

iiδ_i(1,2)\delta\_i(1, 2)δ_i(2,3)\delta\_i(2, 3)
121
212
311

Choosing i=3i = 3 yields the minimum value 11.

예제1

  1. 예제 1

    입력
    3 2
    1 2
    2 3
    3 2
    1 1
    2 2
    3 3
    1 2
    2 3
    3 1
    
    예상 출력
    1
    0
    2