#K251. Message Forwarding Minimization
Message Forwarding Minimization
Message Forwarding Minimization
You are given a directed graph representing employees and their contact lists. Each employee can forward messages to a set of other employees. For each test case, determine the fewest number of forwards required for an employee to send a message to every other employee in the company. If no employee can broadcast a message to everyone, output impossible.
In each test case, the input starts with an integer n representing the number of employees. The next n lines contain the contact information for each employee. Each line begins with an integer k, which indicates the number of contacts, followed by k space-separated integers representing the employees that can be contacted directly. Employees are numbered from 1 to n.
This problem is equivalent to finding a node in the graph with minimal eccentricity. Mathematically, if \(d(u, v)\) denotes the shortest path from vertex \(u\) to vertex \(v\), then the eccentricity of vertex \(u\) is defined as \(\max_{v \in V} d(u,v)\). The goal is to find the minimum eccentricity among all vertices, if such a vertex exists.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer T, the number of test cases.
- For each test case:
- The first line contains an integer n, the number of employees.
- The next n lines each start with an integer k (the number of contacts), followed by k space-separated integers representing the employees that can be reached directly.
outputFormat
For each test case, output a single line to standard output (stdout) containing the minimum number of forwards required for one employee to reach all others. If it is impossible for any employee to reach every other employee, output impossible.
## sample5
3
2 2 3
1 3
0
4
1 2
1 3
0
1 4
1
0
4
1 2
1 3
1 4
0
5
2 2 3
2 4 5
1 4
1 5
0
1
impossible
0
3
2
</p>