Loading...
Loading...
Loading...
There are n tasks. A link a to b means task a must finish before task b can start. Print YES if the tasks can never all finish because some tasks wait for each other in a circle, and NO if an order exists.
Example 1
Input
3 2 0 1 1 2
Output
NO
Example 2
Input
3 3 0 1 1 2 2 0
Output
YES
Try the problem first. Open one hint at a time.
Count how many links enter each task.
Repeatedly remove a task with none, and lower the counts of the tasks it points to.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor