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
Problem Name: Course Schedule
Category: Graph Algorithms
CSES Link: https://cses.fi/problemset/task/1679
Difficulty: [Medium]
📝 Description
This PR adds a complete C++ solution for the Course Schedule problem from CSES, which requires finding a valid order in which all courses can be completed given prerequisite constraints.
Each course represents a node in a directed graph, and each prerequisite relation represents a directed edge. The problem essentially asks for a topological ordering of this graph.
If such an order doesn’t exist (i.e., the graph contains a cycle), the program outputs "IMPOSSIBLE".
🧩 Solution Approach
2)Each time we “take” a course, we remove it and reduce the indegree of its dependents.
3)If all courses are processed → valid order found.
4)If not → cycle detected → impossible to complete all courses.
✅ Checklist
Code Quality
Testing
Documentation
Style Guide
#include <bits/stdc++.h>)🏷️ Type of Change
🧪 Testing Details
Describe how you tested your solution:
To ensure the correctness, performance, and robustness of the solution, I performed several layers of testing:
CSES Judge Verification
Submitted the solution on the official CSES Course Schedule problem
page.
The solution passed all hidden test cases with 0.00s runtime and no memory issues.
Verified the output format matches the expected specification (space-separated order or “IMPOSSIBLE”).
Custom Test Cases
Manually constructed small and edge-case inputs to validate correctness and edge handling
Performance & Efficiency Checks
Ran the solution with maximum input size to verify it runs within CSES time limits.
Checked that the memory footprint remains O(n + m) — suitable for 10⁵ nodes and 2×10⁵ edges.
No stack overflows (since BFS-based), making it safer than DFS for large graphs.
Edge Case Validations
Verified handling of isolated nodes (courses with no prerequisites and not required by others).
Confirmed that cycle detection works by comparing order.size() != n.
Checked behavior when all courses depend on a single root course.
Test Cases Used:
📸 Screenshots
For Maintainers: