Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Bounded Flights

Learn
Play
Prove
Problem context and objectives
Mission briefing

Realm network architect · Routes have costs, dependencies, and unreliable bridges

Choose the next frontier that preserves the route guarantee: The Bounded Flights.

One locally tempting edge can invalidate the whole journey.

How you win

  1. 1Recognize when Edge-bounded Bellman-Ford matches the clues
  2. 2Keep this true after every move: after round r, dist[v] is the cheapest route using at most r edges
  3. 3Reach the result within O((k + 1)E)

Rules and pressure

  • Target cost: O((k + 1)E)
  • State rule: after round r, dist[v] is the cheapest route using at most r edges
Lesson 1 of 3

Live algorithm trace

Edge-bounded Bellman-Ford

Complete execution
1 of 6
0
source
1
2

Before any flight, only city 0 has finite cost.

1dist[src] = 0
2repeat k + 1 rounds
3next = copy(dist)
4for every flight
5next[to] = min(next[to], dist[from] + price)
6dist = next
7return destination or -1
src = 0dst = 2k = 1dist = [0,inf,inf]
Truth to preserve / Cost target
Truth to preserve

after round r, dist[v] is the cheapest route using at most r edges

Cost target

O((k + 1)E)

One copied relaxation round permits one additional edge. Reading only the previous round prevents a newly improved city from chaining multiple flights inside the same edge budget.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead