Added Solution for Flight Discount With proper documentation #140
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Problem Information
#139
Problem Name: Flight Discount
Category: Graphs / Shortest Path (Dijkstra’s Algorithm)
CSES Link: https://cses.fi/problemset/task/1195
Difficulty: Medium
📝 Description
This PR adds the solution for the Flight Discount problem from the CSES Problem Set.
The goal is to find the minimum-cost route from city 1 (Syrjälä) to city n (Metsälä) while optimally using one discount coupon that halves the price of a single flight.
The solution uses a state-based Dijkstra’s algorithm to efficiently handle both the “used” and “unused” discount states for each node.
🧩 Solution Approach
dist[node][0]: Minimum distance without using the discountdist[node][1]: Minimum distance after using the discountdist[n][1], representing the minimum cost after discount usage.✅ Checklist
Please ensure your PR meets these requirements:
Code Quality
Testing
Documentation
Style Guide
#include <bits/stdc++.h>)long longfor large numbers)🏷️ Type of Change
🧪 Testing Details
The solution was tested on both CSES and local environments.
Test Cases Used:
Input:
3 4
1 2 3
2 3 1
1 3 7
2 1 5
Expected Output:
2
Actual Output:
2
Additional tests:
📸 Screenshots
📎 Additional Notes
1 ≤ c ≤ 10⁹).For Maintainers: