335. Course Schedule IV
There are a total of `numCourses` courses you have to take, labeled from `0` to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [a_i, b_i]` indicates that you **must** take course `a_i` first if you want to take course `b_i`. - For example, the pair `[0, 1]` indicates that you have to take course `0` before you can take course `1`. Prerequisites can also be **indirect**. If course `a` is a prerequisite of course `b`, and course `b` is a prerequisite of course `c`, then course `a` is a prerequisite of course `c`. You are also given an array `queries` where `queries[j] = [u_j, v_j]`. For the `j`th query, you should answer whether course `u_j` is a prerequisite of course `v_j` or not. Return a boolean array `answer`, where `answer[j]` is the answer to the `j`th query.
Examples
Input: 5 [[0,1],[1,2],[2,3],[3,4]] [[0,4],[4,0],[1,3],[3,0]]
Output: [true,false,true,false]
Explanation: Along the chain 0→1→2→3→4, 0 reaches 4 and 1 reaches 3, but the reverse directions do not.
Constraints
- 2 <= numCourses <= 100
- 0 <= prerequisites.length <= (numCourses * (numCourses - 1) / 2)
- prerequisites[i].length == 2
- 0 <= a_i, b_i <= numCourses - 1
- All the pairs [a_i, b_i] are unique.
- The prerequisites graph has no cycles.
- 1 <= queries.length <= 10^4
Run checks all cases above. Submit evaluates all test cases.