← 返回 bytedance 的题目列表Course Schedule
类型:online_judge
Course Schedule
There are numCourses courses labeled from 0 to numCourses - 1. You are given prerequisite pairs prerequisites, where [a, b] means that course b must be completed before course a.
Determine whether it is possible to finish all courses. Return false if the prerequisite relationships contain a cycle; otherwise return true.
Input Format
First line: two integers, numCourses m, the number of courses and prerequisite pairs.
Next m lines: two integers a b, meaning course a requires course b.
Output Format
Print true or false.
Example 1
Input:
2 1
1 0
Output:
true
Example 2
Input:
2 2
1 0
0 1
Output:
false
Constraints
1 <= numCourses <= 2 * 10^5
0 <= m <= 2 * 10^5
0 <= a, b < numCourses
Example
Input
2 1
1 0
Output
true