Back to problems

Tree Diameter

Algorithm · Citadel · Medium

Problem: Tree Diameter You are given a tree with n vertices, numbered from 0 through n - 1, along with its n - 1 undirected edges. Output the tree's diameter length, meaning the greatest number of edges in the shortest path connecting any pair of vertices. Input Format The first input line gives the integer n. Each of the following n - 1 lines contains two integers u v, indicating that vertices u and v share an undirected edge. Output Format Print a single integer…

Checking your access…