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
snehil10111995:
20151017 13:41:56
@Mohit, your given graph is not a connected tree. Rather it is a forest with two trees. 

Mohit Rathore:
20151017 07:13:43
Am I misunderstanding the question? For this test case answer should be 3 (4>5>6>7)


kejriwal:
20151012 10:16:36
nice one ! 

[Mayank Pratap]:
20151010 17:03:08
this time using DFS :) 

f3l1pe:
20151005 02:58:52
Si hay alguno de la UTN lo puede resolver, que me mande un mail a lopezfelipeutn@gmail.com con su código; Estoy buscando miembros para competir 

sneh sajal:
20150921 15:13:16
normal recurrsion to get max level!! or you can say bfs or dfs :)


:.Mohib.::
20150917 17:00:47
Nice...!! 

[Mayank Pratap]:
20150916 15:54:02
Good prob to increase confidence in tree.. :) 

Guilherme Sena:
20150908 05:36:36
@Nitesh Tiwari : That is not a tree. (1,2,3,11) is a cycle since edges are undirected. 

Pratik:
20150831 12:08:54
Very good problem with a simple solution 
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 