#C2426. Task Scheduling with Dependencies
Task Scheduling with Dependencies
Task Scheduling with Dependencies
You are given a set of tasks with dependencies. Each task is represented by a unique integer. A task can only be started when all its prerequisite tasks have been completed. In one time unit (or round), you can execute any number of tasks concurrently as long as their dependencies are satisfied.
The tasks are described by a line of numbers. The first number in each line represents the task ID, followed by its dependency task IDs, and terminated by a 0 (which acts as a marker and is not a dependency itself). Your goal is to determine the minimum number of rounds needed to complete all tasks.
In mathematical terms, if \( r_i \) denotes the round in which task \( i \) is executed, then the answer is \( \max_{i} r_i \).
inputFormat
The input is provided from standard input (stdin) in the following format:
- The first line contains a single integer \( n \), the number of tasks.
- The next \( n \) lines each describe a task. Each line starts with the task ID followed by a list of its dependencies (if any) and ends with a 0.
outputFormat
Output a single integer to standard output (stdout) representing the minimum number of rounds required to complete all tasks.
## sample4
1 0
2 1 0
3 1 0
4 2 3 0
3