Graph Theory
시간 제한1초메모리 제한1024 MB
사이클 그래프에서 간선 하나를 제거해 주어진 질의 쌍들의 최단 경로 거리 최댓값을 최소화한다.
문제
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 \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 and .
For the following lines, the -th line contains two integers and .
출력
For each test case, output an integer which denotes the minimum value.
제한
- for each
- In each input, the sum of does not exeed . The sum of does not exceed .
힌트
For the first case,
Choosing yields the minimum value .