Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Course Schedule IV
Bookmark
BFS per Query
Floyd-Warshall
Bitset Floyd-Warshall
Topological Sort
Input
Example 1
Linear Chain
Diamond DAG
Custom
numCourses
=
4
,
prerequisites
=
[[0,1],[0,2],[1,3],[2,3]]
,
queries
=
[[0,3],[3,0],[1,2]]
build graph
queries
0
1
2
3
visited
F
0
F
1
F
2
F
3
queue
0 → 3
3 → 0
1 → 2
build graph
queries
0
1
2
3
visited
F
0
F
1
F
2
F
3
queue
0 → 3
3 → 0
1 → 2
query 1 of 3
queries
0
src
1
2
3
dst
visited
T
0
F
1
F
2
F
3
queue
0 → 3
...
3 → 0
1 → 2
query 1 of 3
queries
0
src
1
2
3
dst
visited
T
0
T
1
F
2
F
3
queue
1
front / rear
0 → 3
...
3 → 0
1 → 2
query 1 of 3
queries
0
src
1
2
3
dst
visited
T
0
T
1
T
2
F
3
queue
2
front / rear
0 → 3
...
3 → 0
1 → 2
query 1 of 3
queries
0
src
1
2
3
dst
visited
T
0
T
1
T
2
T
3
queue
3
front / rear
0 → 3
...
3 → 0
1 → 2
query 1 of 3
queries
0
src
1
2
3
dst
visited
T
0
T
1
T
2
T
3
queue
0 → 3
...
3 → 0
1 → 2
query 2 of 3
queries
0
dst
1
2
3
src
visited
F
0
F
1
F
2
T
3
queue
0 → 3
true
3 → 0
...
1 → 2
query 3 of 3
queries
0
1
src
2
dst
3
visited
F
0
T
1
F
2
F
3
queue
1
front / rear
0 → 3
true
3 → 0
false
1 → 2
...
query 3 of 3
queries
0
1
src
2
dst
3
visited
F
0
T
1
F
2
T
3
queue
3
front / rear
0 → 3
true
3 → 0
false
1 → 2
...
done
queries
0
1
src
2
dst
3
visited
F
0
T
1
F
2
T
3
queue
0 → 3
true
3 → 0
false
1 → 2
false
algo
master
.
io
Step:
Build the adjacency list from 4 courses and 4 prerequisites
0 / 27
Input
Example 1
Linear Chain
Diamond DAG
Custom
numCourses
=
4
,
prerequisites
=
[[0,1],[0,2],[1,3],[2,3]]
,
queries
=
[[0,3],[3,0],[1,2]]
0 / 27
algo
master
.
io
Step:
Build the adjacency list from 4 courses and 4 prerequisites