MediumRating 1693
1462. Course Schedule IV
depth-first-searchbreadth-first-searchgraphtopological-sort
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Create n x n boolean matrix reachable (all false)
2. For each prerequisite [u, v]: set reachable[u][v] = true
3. Floyd-Warshall transitive closure:
For k from 0 to n-1:
For i from 0 to n-1:
For j from 0 to n-1:
If reachable[i][k] and reachable[k][j]:
reachable[i][j] = true
4. For each query [u, v]: append reachable[u][v] to result
5. Return result