Class Solution
- java.lang.Object
-
- g1401_1500.s1462_course_schedule_iv.Solution
-
public class Solution extends Object
1462 - Course Schedule IV.Medium
There are a total of
numCoursescourses you have to take, labeled from0tonumCourses - 1. You are given an arrayprerequisiteswhereprerequisites[i] = [ai, bi]indicates that you must take courseaifirst if you want to take coursebi.- For example, the pair
[0, 1]indicates that you have to take course0before you can take course1.
Prerequisites can also be indirect. If course
ais a prerequisite of courseb, and coursebis a prerequisite of coursec, then courseais a prerequisite of coursec.You are also given an array
querieswherequeries[j] = [uj, vj]. For thejthquery, you should answer whether courseujis a prerequisite of coursevjor not.Return a boolean array
answer, whereanswer[j]is the answer to thejthquery.Example 1:

Input: numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]
Output: [false,true]
Explanation: The pair [1, 0] indicates that you have to take course 1 before you can take course 0. Course 0 is not a prerequisite of course 1, but the opposite is true.
Example 2:
Input: numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]
Output: [false,false]
Explanation: There are no prerequisites, and each course is independent.
Example 3:

Input: numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]
Output: [true,true]
Constraints:
2 <= numCourses <= 1000 <= prerequisites.length <= (numCourses * (numCourses - 1) / 2)prerequisites[i].length == 20 <= ai, bi <= n - 1ai != bi- All the pairs
[ai, bi]are unique. - The prerequisites graph has no cycles.
1 <= queries.length <= 1040 <= ui, vi <= n - 1ui != vi
- For example, the pair
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Boolean>checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries)
-