Find Distance

0

0 votes
Tree
Problem

There are N nodes of a tree,your task is to find maximum distance between two nodes if you don't know how to get maximum distance (longest path)  between any two nodes of the given tree, you can also take a help from your friend.

Input format : 

The first input line contains an integer N: the number of nodes. The nodes are numbered 1,2,…,N.

Then there are N−1 lines describing the edges. Each line contains two integers A and B : there is an edge between nodes A and B.

Output format : 

Print one integer: the maximum distance betwen two nodes of the tree.

Constraints : 

1 ≤ N≤ 2⋅10e5

1 ≤ A,B ≤ N

Example : 

Input :
5
1 2
1 3
3 4
3 5

Output :
3

Explanation : 

         1

       /   \

     2     3

           /   \

         4      5

maximum distance is between  node 2 and node 5

2 -> 1 -> 3 -> 5

Author :

Sushant Singh

Bipul Kumar 

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?