1479. Graph Theory

Bobo has an undirected graph GG with nn vertices labeled by 1,,n1, \dots, n and nn edges. For each 1in1 \leq i \leq n, there is an edge between the vertex ii and the vertex (imodn)+1(i \bmod n) + 1. He also has a list of mm pairs (a1,b1),,(am,bm)(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 (imodn)+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(a1,b1),,δi(am,bm)\delta_i(a_1, b_1), \dots, \delta_i(a_m, b_m).

Formally, find the value of min1in{max1jmδi(aj,bj)} \min_{1 \leq i \leq n}\{\max_{1 \leq j \leq m} \delta_i(a_j, b_j)\}

输入

Note from SCNUOJ admin: we don't have the official test data sets, and all tests used here are randomly generated, so expect weak tests and/or even wrong input format. Contact one of the admins if you wish to improve the tests.

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 aia_i and bib_i.

  • 2n2×1052 \leq n \leq 2 \times 10^5
  • 1m2×1051 \leq m \leq 2 \times 10^5
  • 1ai,bin1 \leq a_i, b_i \leq n for each 1im1 \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 each test case, output an integer which denotes the minimum value.

样例

标准输入 复制文本
3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1
标准输出 复制文本
1
0
2
标准输入 复制文本
2 1
1 2
标准输出 复制文本
1

提示

For the first case,

iiδi(1,2)\delta_i(1, 2)δi(2,3)\delta_i(2, 3)
112211
221122
331111

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

来源

第六届中国大学生程序设计竞赛总决赛

登录以提交代码。
单点时限 1 秒
内存限制 128 MB
提交 9
通过 5