Longest Cycle

For this question we ask you to compute the length of the longest possible cycle on a tree after adding an edge to a graph connecting any 2 nodes in a graph. As a reminder, a tree is a special subset of graphs that have n nodes, n - 1 edges and possess no cycles. The input will have n the number of nodes in the tree where the nodes will be numbered from 1 to n. t Then, a list of size n -1 called edges denoting the edges in the graph. It should be noted that adding any 1 edge to a tree will make at least 1 cycle in the graph.

Constraints

1 <= n <= 100000

Examples:

Example 1:
Input 1: n = 4, edges = [[1, 2], [2, 3], [2, 4]]
Output 1: 3
Explanation:

We connect the edge between nodes 1 and 3 thus creating a cycle of size 3 which is the longest possible cycle.

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade