Graph Theory37 sections · 1633 units
Open in Course

CSES 1195 Flight Discount - Problem Statement

One-time discount optimization

You have a directed graph of cities with flight prices. You want the cheapest route from city 11 to city n. You can use a 5050% discount coupon on exactly one flight. If you use standard Dijkstra, you get the cheapest path without the discount.

But maybe using the discount on an expensive flight gives you a cheaper total.

The trick: track whether you've used the discount or not as part of your state. Your state is (city, discount_used). You run Dijkstra on this expanded state space.