Tree Diameter For Each Testcase

Programming Interview Hard 5 views
Back to Questions

Problem Description

For each testcase you get a tree with n nodes. Output the diameter length (number of edges on longest path).

Input Format

First integer t. For each: n then n-1 edges u v (1-based).

Output Format

t lines diameter length.

Sample Test Case

Input:
1 5 1 2 2 3 3 4 2 5
Output:
3

Constraints

Sum of n over all testcases

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next