3
one approach I can think of is, given a graph,4
the query[a, b] will be true if there exists a path from a to b in the graph5
else a will not be a prerequisite of b6
but this approach may not scale as the # of queries will increase9
def checkIfPrerequisite(10
self, numCourses: int, prerequisites: List[List[int]], queries: List[List[int]]12
graph = {node: set() for node in range(numCourses)}13
for pre in prerequisites:14
graph[pre[0]].add(pre[1])16
def path(cur_node, node_b):17
if cur_node == node_b:19
for neighbor in graph[cur_node]:20
if path(neighbor, node_b):26
# see if there is a path from query[0] to query[1]27
ans.append(path(query[0], query[1]))