#K53637. Task Scheduler with Dependency Check

    ID: 29576 Type: Default 1000ms 256MiB

Task Scheduler with Dependency Check

Task Scheduler with Dependency Check

You are given a task scheduling system where tasks may depend on other tasks. Each task is identified by an integer ID. A task x can be added using the command addTask x y, which means task x is added and it depends on task y being completed first. A dependency value of 0 means that the task has no prerequisites.

You can mark a task as completed with markComplete x. However, a task can only be marked as completed if all tasks it depends on are already completed. Finally, the command getIncompleteTasks outputs all tasks that have not been completed yet, sorted in ascending order. If all tasks are completed, output None.

In mathematical terms, if a task x has a set of dependencies \(D(x)\), then task x can be completed if and only if \(\forall d \in D(x),\ d \text{ is completed}\).

inputFormat

The input is given via standard input (stdin). The first line contains an integer n, the number of commands. The next n lines each contain one command. Each command is one of the following:

  • addTask x y — Add a task with ID x. If y is not 0, then task x depends on task y.
  • markComplete x — Mark task x as completed if all its dependencies were completed.
  • getIncompleteTasks — Print all incomplete tasks in sorted order (by IDs). If no tasks remain, print "None".

outputFormat

For each getIncompleteTasks command, output the incomplete task IDs sorted in increasing order, separated by a space. If all tasks are complete, output None. The outputs for different getIncompleteTasks commands should be printed on separate lines to stdout.

## sample
8
addTask 1 0
addTask 2 1
addTask 3 1
getIncompleteTasks
markComplete 1
getIncompleteTasks
markComplete 2
getIncompleteTasks
1 2 3

2 3 3

</p>