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.
Example 1
Input: numCourses = 5, prerequisites = [[0,1],[1,2],[2,3],[3,4]], queries = [[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.
Example 2
Input: numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]
Output: [false,true]
Explanation: 1 is a prerequisite of 0, not vice versa.
Example 3
Input: numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]
Output: [false,false]
Explanation: No prerequisites at all.
Precompute for every pair (i, j) whether i is a (direct or indirect) prerequisite of j. That's the transitive closure of the prerequisite graph, which Floyd-Warshall computes in O(V^3); each query is then an O(1) lookup.
Run checks all cases above. Submit evaluates all test cases.