#K92487. Hierarchy Depth Analysis
Hierarchy Depth Analysis
Hierarchy Depth Analysis
You are given a company hierarchy in the form of a tree rooted at the CEO (employee 1). The input consists of the number of employees N and N-1 pairs of integers. Each pair represents an edge in the hierarchy where the first number is the manager and the second is his/her direct subordinate.
Your task is to determine the maximum depth of the tree (i.e. the largest distance from the root) and count the number of employees that are at this maximum depth.
Formally, if we denote the depth of the root (employee 1) as 0, then for any employee, the depth is defined as the number of edges on the path from the root to that employee. Let \( D_{max} \) be the maximum depth achieved in the tree. You need to compute and output both \( D_{max} \) and the number of employees whose depth is exactly \( D_{max} \).
Example: Consider a hierarchy with 7 employees and the following relationships:
1 2 1 3 2 4 2 5 3 6 3 7
Here, the maximum depth is 2 and there are 4 employees at depth 2, so the output is 2 4
.
inputFormat
The input is read from stdin and has the following format:
N manager_1 subordinate_1 manager_2 subordinate_2 ... (N-1 lines in total)
Here, N is the number of employees, numbered from 1 to N, and each subsequent line contains two integers representing a manager and a subordinate.
outputFormat
Output a single line to stdout containing two space-separated integers: the maximum depth \(D_{max}\) of the hierarchy tree and the number of employees at that depth.
For instance, for the sample input, the output should be:
2 4## sample
7
1 2
1 3
2 4
2 5
3 6
3 7
2 4