Kernel Scheduler
Time limit2sMemory limit1024 MB
Given n tasks and m directed dependencies, keep at least m/2 of them so that the kept dependencies contain no cycle and print their ids.
- Level
Medium5 of 10
- Topics
- Graph, Topological sort, Greedy
- Solved
- No attempts yet
Problem
You are developing the scheduling module for a new operating system. The module takes tasks to execute and the dependencies between them, then puts them in an order for execution.
More formally, the tasks are numbered from 1 to . You are given dependencies numbered from 1 to . The -th dependency is described by two numbers and , meaning that task must be executed before task .
Sometimes there are cyclical dependencies: task must run before , before , ..., before , and before . Cyclical dependencies break scheduling, so you must remove some of the given dependencies so that the remaining set has no cycles.
However, you still need to keep at least of the original dependencies to preserve some of the original information. Write a program that performs this task.
Input
The first line contains and (, ). Each of the next lines contains two numbers and (, ), describing the corresponding dependency between tasks and .
Output
The first line should contain YES if the desired subset of dependencies exists, and NO otherwise. In the YES case, the second line contains the number of selected dependencies (note that must be at least ), and the third line contains the ids of the selected dependencies. The ids are numbered from 1 to in input order.