Scrooge Minho
InterviewTime limit2sMemory limit512 MB
Given a tree, place one fire station at the vertex minimizing the maximum distance to any other vertex, and output that distance.
Problem
Minho, a famously stingy king, rules a country with cities. To keep the cost of building roads down he built only roads, so between any two cities there is exactly one route.
Minho did not want to pay for several fire stations either, so he decided to build a single fire station in one city. He does pick the best possible city for it. The best position is the city that minimizes the largest distance a fire truck has to travel from that city to reach some other city. Travel inside one city costs nothing, and driving along one road costs a distance of 1.
Given the number of cities and the roads between them, write a program that finds the largest distance a fire truck travels from the fire station built at the best position to reach another city.
Input
The first line contains the number of cities ().
Each of the next lines describes one road. A line contains two integers and () separated by a space, meaning city and city are joined by a two-way road. The roads connect all cities into one piece.
Output
Print on the first line the largest distance a fire truck travels from the fire station built at the best position to reach another city.