#K81122. Minimum Discussion Rounds in a Hierarchical Company
Minimum Discussion Rounds in a Hierarchical Company
Minimum Discussion Rounds in a Hierarchical Company
You are given a hierarchical company structure in which each employee has a direct reporting relationship (from a manager to a subordinate). In each round, all employees who have no pending reports (i.e. all of their managers have already participated) can join the discussion. Your task is to determine the minimum number of rounds required to complete the round-robin discussion. Formally, if the company structure forms a rooted tree (or a forest), then the minimum rounds correspond to the number of levels in its topological ordering.
Note that even if there is only one employee, the discussion rounds is defined as 1.
Input Constraints: The input consists of multiple test cases. For each test case, you are given the number of employees along with the direct reporting pairs.
Example:
Input: 2 3 2 1 2 1 3 5 4 1 2 1 3 3 4 3 5</p>Output: 2 3
inputFormat
The input begins with an integer T representing the number of test cases. Each test case is described as follows:
- The first line contains an integer N representing the number of employees.
- The next line contains an integer M representing the number of direct reporting pairs.
- Each of the following M lines contains two space-separated integers u and v indicating that employee u is the manager of employee v.
It is guaranteed that the relationships form a valid hierarchy.
outputFormat
For each test case, output a single integer representing the minimum number of discussion rounds required. The result for each test case should be printed on a new line.
## sample2
3
2
1 2
1 3
5
4
1 2
1 3
3 4
3 5
2
3
</p>