## VM7WC '16 #5 Gold - Jayden Studies Trees

View as PDF

Points: 7
Time limit: 0.6s
Memory limit: 64M

Author:
Problem types

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.

#### Input Specification

The first line will have . The next lines will each contain two integers and , denoting that an edge connects node with node .

#### Output Specification

On a single line, print the longest path between any two nodes in the tree.

#### Sample Input

6
1 2
1 3
2 4
2 5
5 6

#### Sample Output

4

#### 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)

will be the maximum number of calls that a recursive function can call. If you set to be too big, Python might run out of memory when performing the recursive calls and generate a Segmentation Fault. Try to keep as low as possible.

• commented on Feb. 8, 2016, 2:31 a.m.

So when it says it connects node x to node y that path goes both ways right?

• commented on Feb. 8, 2016, 7:24 p.m.

yup

• commented on Feb. 5, 2016, 8:45 p.m.

Is the output 4 because there is a path of length 4?

• commented on Feb. 5, 2016, 8:56 p.m.

You're right, it has been fixed.