David's Magic Sloth

Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 512M

Problem type

Sloths live, nay, thrive in trees. Obviously David has a pet sloth that he lets play on his unweighted trees while solving programming problems. Sloths are typically very slow creatures but David's sloth (Jeff for those invested) has the ability to teleport around the tree at will (but only on the tree, Jeff is still lazy at heart).

What is the furthest possible distance David's magic sloth can travel in a given tree?

Background: A tree is a graph with \(n\) nodes, \(n-1\) edges and no cycles. They have the other fun property that shortest paths between nodes are unambiguous.

Input Specification

The first line contains an integer \(n (1 \leq n \leq 3 \times 10^5), the number of vertices in the tree\).

The next \(n-1\) lines contain two space-separated integers \(a,b (1 \leq a,b \leq n)\) describing the endpoint of each edge present in the tree. You are guaranteed that all inputs form valid trees.

Output Specification

A single integer; the maximum distance David's sloth can teleport.

Sample Input 1


Sample Output 1


Sample Input 2

3 1
1 2

Sample Output 2


Sample Input 3

3 1
1 2
4 2
5 2

Sample Output 3



There are no comments at the moment.