Bobo has an undirected graph with vertices labeled by and edges. For each , there is an edge between the vertex and the vertex . He also has a list of pairs .
Now, Bobo is going to choose an and remove the edge between the vertex and the vertex . Let be the number of edges on the shortest path between the -th and the -th vertex after the removal. Choose an to minimize the maximum among .
Formally, find the value of
输入
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 and .
For the following lines, the -th line contains two integers and .
输出
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,
Choosing yields the minimum value .
来源
第六届中国大学生程序设计竞赛总决赛