#C1538. Minimum Communication Rounds
Minimum Communication Rounds
Minimum Communication Rounds
In a company with \( n \) employees and \( m \) one-way communication links, a message is initiated by employee \( s \). In each communication round, every employee who has received the message can pass it on to each of their direct contacts. Your task is to determine the minimum number of rounds required so that all employees receive the message.
If it is impossible for all employees to be reached, output \( -1 \).
inputFormat
The input is read from stdin
and consists of multiple test cases. The first line contains an integer \( T \) representing the number of test cases. Each test case begins with a line containing three integers \( n \), \( m \), and \( s \) representing the number of employees, the number of communication links, and the starting employee, respectively. This is followed by \( m \) lines, each containing two integers \( u \) and \( v \), indicating a one-way communication link from employee \( u \) to employee \( v \).
outputFormat
For each test case, output a single line (to stdout
) containing the minimum number of communication rounds required for all employees to receive the message. If some employees cannot be reached, output \( -1 \).
3
4 4 1
1 2
1 3
3 4
2 4
5 3 1
1 3
3 5
2 4
3 3 1
1 2
2 3
3 1
2
-1
2
</p>