#P2185. 公路通行税
公路通行税
Description
In the country of PALMIA, there are cities connected by roads (each road connects exactly two cities bidirectionally). From any city, it is possible to reach every other city by traveling along one or more roads. Starting this year, a highway toll will be charged. In the middle of each road, there is a tax collector who collects 1 PALMIA COIN (1 PC) from every car that uses this road.
Government officials decided to reduce the number of tax collectors by introducing a road stamp. If a car wants to enter a road, it must stick this stamp on its window.
The officials set the annual road stamp value to be equal to the total cost of making trips between the two farthest cities. The distance between two cities is defined as the minimum number of roads that must be traversed to get from one city to the other.
Your task is to write a program to compute the value of the road stamp.
Input Format
The input contains multiple test cases. The first line of each test case contains two integers and (separated by a space), where is the number of cities and is the number of roads (, ). Cities are labeled with integers from to . Each of the next lines contains a pair of integers , (), separated by a space, indicating that there is a road between city and city . The input terminates with a line containing two zeros separated by a space.
Output Format
For each test case, output one line containing the value of the road stamp.
4 4
1 2
2 3
4 2
3 4
0 0
200
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号