← 返回 amazon 的题目列表Course Schedule
类型:online_judge
Problem: Course Schedule
You need to finish numCourses courses labeled from 0 to numCourses - 1.
Given an array prerequisites, where each pair [a, b] means you must take course b before course a.
Return whether it is possible to finish all courses. Print true if possible, otherwise print false.
Input Format
The first line contains two integers n and m, representing the number of courses and the number of prerequisite relations.
The next m lines each contain two integers a b, meaning course b must be taken before course a.
Output Format
Print true if all courses can be finished.
Otherwise, print false.
Constraints
1 <= n <= 10^5
0 <= m <= 2 * 10^5
0 <= a, b < n
The prerequisite graph may contain cycles.
Example
Input
2 1
1 0
Output
true