IRCTC Subsidised Route Bellman-Ford
IRCTC Subsidised Route Bellman-Ford
HardGraphs0% accepted
IRCTC has n stations. Some routes have subsidized fares (negative weights). Find shortest path from source to all stations; detect if any negative-weight cycle exists making cost unbounded.
Approach
Single-source shortest path with negative weights and cycle detection (Bellman-Ford).
Input
5 8 0
0 1 -1
0 2 4
1 2 3
1 3 2
1 4 2
3 2 5
3 1 1
4 3 -3
Output
0 -1 2 -2 1
More Graphs problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards