Learn
Practice
Newsletter
Resources
F
Toggle theme
0
F
Toggle theme
0
Toggle menu
← Back to All Animations
787. Cheapest Flights Within K Stops
Bookmark
Input
4 Nodes (k=1)
3 Nodes (k=1)
5 Nodes (k=2)
Custom
n
=
4
,
flights
=
[[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]]
,
src
=
0
,
dst
=
3
,
k
=
1
Cheapest Flights Within K Stops (0 → 3)
Initializing...
100
100
100
600
200
0
1
2
3
0
∞
∞
∞
dist[]:
0
0
1
∞
2
∞
3
∞
Legend:
Unprocessed
Source
Active
Destination
Updated
algo
master
.
io
Step:
Initialize dist array: dist[0] = 0, all others = Infinity. Find cheapest price from 0 to 3 with at most 1 stops.
0 / 27
Input
4 Nodes (k=1)
3 Nodes (k=1)
5 Nodes (k=2)
Custom
n
=
4
,
flights
=
[[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]]
,
src
=
0
,
dst
=
3
,
k
=
1
0 / 27
Cheapest Flights Within K Stops (0 → 3)
Initializing...
100
100
100
600
200
0
1
2
3
0
∞
∞
∞
dist[]:
0
0
1
∞
2
∞
3
∞
Legend:
Unprocessed
Source
Active
Destination
Updated
algo
master
.
io
Step:
Initialize dist array: dist[0] = 0, all others = Infinity. Find cheapest price from 0 to 3 with at most 1 stops.