Back to Browse

Flight Discount (CSES) | Modified Dijkstra’s Algorithm with State

1.0K views
Jul 3, 2025
23:37

✈️ You’ve got one chance to use a discount on a flight — where do you use it to minimize your total travel cost? 📄 𝐍𝐨𝐭𝐞𝐬: https://github.com/yash7xm/cp_notes/tree/master/cses/graphs In this video, we solve the Flight Discount problem from the CSES Problem Set using a smart modification of Dijkstra’s Algorithm. We introduce the concept of stateful shortest paths, where each node is visited in two states: before using the discount and after using it. We walk you through how to implement a 2D distance array dist[node][state], why a priority queue of tuples is needed, and how to make optimal decisions under constraints. This is a real-world simulation of how algorithms adapt to dynamic conditions — a must-know trick in advanced competitive programming. If you're looking to level up your graph skills and understand how to extend classic algorithms to new problems, this one's for you. #ModifiedDijkstra #GraphAlgorithms #CSES #FlightDiscount #CompetitiveProgramming

Download

1 formats

Video Formats

360pmp428.5 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Flight Discount (CSES) | Modified Dijkstra’s Algorithm with State | NatokHD