PT07Z  Longest path in a tree
You are given an unweighted, undirected tree. Write a program to output the length of the longest path (from one node to another) in that tree. The length of a path in this case is number of edges we traverse from source to destination.
Input
The first line of the input file contains one integer N  number of nodes in the tree (0 < N <= 10000). Next N1 lines contain N1 edges of that tree  Each line contains a pair (u, v) means there is an edge between node u and node v (1 <= u, v <= N).
Output
Print the length of the longest path on one line.
Example
Input: 3 1 2 2 3 Output: 2
hide comments
sarvesh_19:
20160616 21:44:07
famous graph problem (easy). N<=10000 array repn giving RTE and TLE...use adjacency list *only trick in this q*. 

praval_singhal:
20160519 16:48:16
I submitted the same code 1 hr ago. got WA. Now AC. what the F :P 

Shreyans:
20160413 12:46:58
Last edit: 20160413 22:43:12 

Ram:
20160331 22:12:13
Finally got AC..!! Got WA repeatedly while using start node as 1. Changed the start node from 1 to last node and it got accepted. Please notify if there is anything wrong in my code.


sharif ullah:
20160314 09:47:06
just find the diameter of a tree.2 bfs.needed!!!!!!!!!!!! 

rohit123456:
20160305 12:28:44
done in a single dfs 

newbie:
20160130 14:18:18
answer is 5 

newbie:
20160130 14:17:44
simple dfs accepted in 0.00 s


dwij28:
20160115 06:29:00
Did it by using bfs twice, what is the dfs way of doing it ? If anyone could please provide some helpful link for solving it with dfs.. 

dark_lord1:
20151226 00:12:43
Using a 2D matrix of type char to store edge information gives runtime error..But using adjacency list to store graph give AC....How can the 2D matrix possibly exceed memory available?? Costed me 2 RE. :( 
Added by:  ThanhVy Hua 
Date:  20070328 
Time limit:  0.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  Coauthor Amber 