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 Threshold City

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 Threshold City.

One locally tempting edge can invalidate the whole journey.

How you win

  1. 1Recognize when Floyd-Warshall threshold counting matches the clues
  2. 2Keep this true after every move: the distance matrix contains the cheapest path between every city pair
  3. 3Reach the result within O(V cubed)

Rules and pressure

  • Target cost: O(V cubed)
  • State rule: the distance matrix contains the cheapest path between every city pair
Lesson 1 of 3

Live algorithm trace

Floyd-Warshall threshold counting

Complete execution
1 of 6
0
city
1
2
3

Build the symmetric direct-distance matrix.

1build an undirected distance matrix
2run Floyd-Warshall
3for each city
4count other cities within threshold
5replace answer on count <= best
6return greatest tied index
threshold = 4directEdges = 4
Truth to preserve / Cost target
Truth to preserve

the distance matrix contains the cheapest path between every city pair

Cost target

O(V cubed)

After all-pairs shortest paths, count for each city how many others lie within the distance threshold. Select the smallest count, breaking ties toward the greatest city index.

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