CF909E Coprocessor
题目描述
给你 $N$ 个任务,任务从 $0$ 开始标号,有些只能用主处理器处理,另外的任务只能用副处理器处理。其中存在 $M$ 个依赖关系,如果任务 $i$ 依赖于任务 $j$,那么称 $j$ 是 $i$ 的前继任务。
主处理器和副处理器都可以一次处理很多个任务。一个任务能被处理的条件为其所有的前继任务已经被执行过了,或者前继任务和自己同时被放进同一个处理器处理。
现在给出这些依赖关系和每个任务处理要用的处理器,求副处理器最少运行了几次。保证依赖关系是一张有向无环图。
输入格式
无
输出格式
无
说明/提示
In the first test, tasks 1 and 3 can only be executed on the coprocessor. The dependency graph is linear, so the tasks must be executed in order 3 -> 2 -> 1 -> 0. You have to call coprocessor twice: first you call it for task 3, then you execute task 2 on the main processor, then you call it for for task 1, and finally you execute task 0 on the main processor.
In the second test, tasks 0, 1 and 2 can only be executed on the coprocessor. Tasks 1 and 2 have no dependencies, and task 0 depends on tasks 1 and 2, so all three tasks 0, 1 and 2 can be sent in one coprocessor call. After that task 3 is executed on the main processor.