GCPC11J  Time to live
As you might know, most computer networks are organized in a treelike fashion, i.e. each computer is reachable by each other computer but only over one, unique path.
The socalled Time to live (TTL) specifies after how many hops a network packet is dropped if it has not reached its destination yet. The purpose of the TTL is to avoid situations in which a packet circulates through the network caused by errors in the routing tables.
The placement of a router that connects the network to another network is optimal when the maximal needed TTL for packets that are sent from this router to any other computer within the same network is minimal. Given a network as specified above, you should calculate the maximal needed TTL in this network if you can select the computer that should be used as router.
Input
The first line of the input consists of the number of test cases c that follow (1 ≤ c ≤ 100). Each test case starts with a line specifying N, the number of computers in this network (1 < N ≤ 10^{5}). Computers are numbered from 0 to N1. Then follow N1 lines, each specifying a network connection by two numbers a and b which means that computer a is connected to computer b and vice versa, of course (0 ≤ a,b < N).
Output
For each test case in the input, print one line containing the optimal TTL as specified above.
Example
Input: 3 2 1 0 5 3 2 2 1 0 2 2 4 9 3 1 6 5 3 4 0 3 8 1 1 7 1 6 2 3 Output: 1 1 2
hide comments
yash_999:
20200112 20:04:14
Last edit: 20200112 20:04:30 

its_himanshu:
20191213 12:59:04
AC in one go. 

kkmeliodus:
20190729 19:35:03
you have to find the radius of the tree


debsourav33:
20181225 09:47:48
Great (basic) problem to attempt in/out DP for the first time! Diameter finding will work too 

jkks1234:
20181129 13:40:55
Just find the longest path.As the max hop will be equal (max dist between 2 nodes)/2. 

harvy98:
20180528 13:26:05
Use BufferedReader with Adjacency List in Java. Tree Diameter approach. 

ameyanator:
20180327 21:52:54
Prerequisite for this question is >http://www.spoj.com/problems/PT07Z/ 

aniket000:
20171229 07:49:38
any code optimization tips to avoid TLE ? , pls? :(( , im calculating levels using bfs on each vertex and storing the maximum level from each vertex and finally returning the smallest level gathered.


vipul_0751:
20171210 07:28:31
use double dfs 

vanamala:
20171209 13:50:51
Can someone help me, sharing their code. ? Last edit: 20171209 13:51:14 
Added by:  Adrian Kuegel 
Date:  20110705 
Time limit:  1.807s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  German Collegiate Programming Contest 2011 (Author: Tobias Werth) 