#C1641. Maximum Distance in Company Hierarchy
Maximum Distance in Company Hierarchy
Maximum Distance in Company Hierarchy
In this problem, you are provided with the structure of a company organized as a tree. The CEO is represented by employee 1 and every other employee reports directly to exactly one supervisor. Each subsequent line in the input describes a reporting relationship between two employees. Your task is to compute the maximum distance from the CEO to any employee in the hierarchy.
Formally, let (d(i)) be the number of edges in the unique path from the CEO (employee 1) to employee (i). You need to calculate:
[ \max_{1 \leq i \leq n} d(i) ]
where ( n ) is the total number of employees.
inputFormat
The first line contains an integer ( n ) ((1 \leq n \leq 10^5)) representing the total number of employees. Each of the next ( n-1 ) lines contains two integers ( a ) and ( b ) ((1 \leq a, b \leq n)) indicating that employee ( a ) directly reports to employee ( b ). It is guaranteed that the input forms a tree with employee 1 as the CEO.
outputFormat
Output a single integer representing the maximum distance (number of reporting steps) from the CEO to any employee in the company.## sample
5
2 1
3 1
4 2
5 3
2