Jayden is a little kid that likes to study trees. From the last problem, Jayden has cut down many trees. Each tree is an undirected graph where any two nodes are connected by exactly one path. Jayden would like to find the length of the longest of the paths. That means that he wants you to do it for him.
The first line will have ~N~ ~(1 \leq N \leq 10^4)~. The next ~N-1~ lines will each contain two integers ~x~ and ~y~ ~(1 \leq x,y \leq N)~, denoting that an edge connects node ~x~ with node ~y~.
On a single line, print the longest path between any two nodes in the tree.
6 1 2 1 3 2 4 2 5 5 6
Reaching the recursion limit on Python?
You can increase the amount of calls a recursive program in Python with the following code:
import sys sys.setrecursionlimit(x) #x will be the maximum number of calls that a recursive function can call.
If you set ~x~ to be too big, Python might run out of memory when performing the recursive calls and generate a Segmentation Fault. Try to keep ~x~ as low as possible.