Scientific Project
The scientific project comprises N
tasks, each executed on one of the N
processors of a supercomputer. Tasks can run concurrently, but some tasks depend on the completion of others. For each task, the execution time and a list of prerequisite tasks that must be finished beforehand are provided (this list can be empty).
Determine the minimum time required to complete all N
tasks in the project, or output -1
if it's impossible to complete the project. All input numerical values are natural numbers, not exceeding 100.
Input Data
The first line contains the integer N
. The following N
lines provide the execution time and the list of prerequisite tasks (if any) for each task.
Output Data
Output a single number representing the minimum time needed to complete the project, or -1
if the project cannot be completed.